Table of Contents

Práctica Final

  • Curso: Machine Learning
  • Integrantes:
    • Marina Ortín
    • Mayra Goicochea
In [2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib import rcParams
%matplotlib inline

Objetivos

El objetivo de este ejercicio es el desarrollo de un modelo que permita la identificación de prestamistas que puedan realizar un impago en el crédito concedido. En este sentido, probaremos varios modelos, desde regresión logística a XGBoost, con el objetivo de encontrar el modelo óptimo. En este sentido, nos remitimos al apartado "KPI", en el que definimos los indicadores de desempeño que guiarán nuestra decisión.

Para ello, es necesario analizar qué variables son determinantes para la concesión del crédito. Este estudio se puede encontrar en el epígrafe "Análisis exploratorio (EDA)".

KPI

En este apartado describiremos brevemente los indicadores de performance que utilizaremos para elegir el mejor modelo.

Aunque nos basaremos en la medida de accuracy, tomaremos otras medidas adicionales, como la matriz de confusión, área bajo la curva (AUC) y F1 Score.

Definimos accuracy como el ratio entre el número de predicciones correctas realizadas por el modelo y el número total de observaciones input. Se trata de la medida básica que utilizamos para la selección de modelos; sin embargo, realizaremos cálculos adicionales como:

  • Matriz de confusión: se trata de una matriz que describe, de forma completa, el desempeño del modelo. De esta forma, se puede observar en la diagonal principal el número de aciertos del modelo, así como los falsos negativos y falsos positivos que ha devuelto.

  • Área bajo la curva (AUC), curva ROC: esta medida es ampliamente utilizada en problemas de clasificación binaria, como este. Se trata de una representación gráfica que, dado un umbral de clasificación, representa sensibilidad y especificidad del modelo.

  • F1 Score: se trata de una medida de la accuracy. Matemáticamente, se calcula como la media armónica entre precisión y recall. Cabe recordar, en este sentido, que la precisión se define como el número de positivos acertados sobre el número de aciertos total.

$Precision = \frac{TruePositives}{TruePositives + FalsePositives}$

Mientras que el recall es el número de verdaderos positivos sobre el total de muestras que deberían haberse identificado como positivas.

$Recall = \frac{TruePositives}{TruePositives + FalseNegatives}$

Datos

Mediante revisión previa en el archivo del dataset, se observa que tiene 2.260.668 registros almacenados con 145 columnas. La columna id, member_id y url no tienen propiedad discriminante para el análisis de concesión de créditos es así que no serán consideradas en el dataset final. También se muestra que se tiene una columna loan_status de la cual se considerará sólo las categorías "Default","Charged Off" y "Fully Paid" que se trata de préstamos históricos que tomaremos de referencia para detectar las dos clases "Default" (préstamos impagos) y "No Default" (préstamos pagados). Dada éstas condiciones se procede a la carga del pandas dataframe loan con estas restricciones:

In [3]:
chunksize = 1000
status_set = ['Fully Paid',
              'Charged Off',
              'Does not meet the credit policy. Status:Fully Paid',
              'Does not meet the credit policy. Status:Charged Off',
              'Default']
all_loans = pd.concat([chunk[chunk['loan_status'].isin(status_set)]
                for chunk in pd.read_csv('../data/loan.csv', chunksize=chunksize)])
In [4]:
loan =all_loans.drop(['id','member_id','url'],1)
In [5]:
loan.info()
loan.describe()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 1306387 entries, 100 to 2260664
Columns: 142 entries, loan_amnt to settlement_term
dtypes: float64(102), int64(4), object(36)
memory usage: 1.4+ GB
Out[5]:
loan_amnt funded_amnt funded_amnt_inv int_rate installment annual_inc dti delinq_2yrs inq_last_6mths mths_since_last_delinq ... deferral_term hardship_amount hardship_length hardship_dpd orig_projected_additional_accrued_interest hardship_payoff_balance_amount hardship_last_payment_amount settlement_amount settlement_percentage settlement_term
count 1.306387e+06 1.306387e+06 1.306387e+06 1.306387e+06 1.306387e+06 1.306383e+06 1.306075e+06 1.306358e+06 1.306357e+06 647355.000000 ... 5335.0 5335.000000 5335.0 5335.000000 3433.000000 5335.000000 5335.000000 32003.000000 32003.000000 32003.000000
mean 1.440552e+04 1.439643e+04 1.436810e+04 1.325918e+01 4.377787e+02 7.614879e+04 1.825024e+01 3.174559e-01 6.664786e-01 34.303021 ... 3.0 148.212679 3.0 13.968510 414.084599 11028.726163 184.578017 5051.677568 47.669719 13.088429
std 8.698613e+03 8.694589e+03 8.700952e+03 4.757423e+00 2.610471e+02 7.004582e+04 1.093374e+01 8.770225e-01 9.640143e-01 21.931669 ... 0.0 129.101351 0.0 9.766266 360.416982 7466.642417 195.413041 3687.945922 7.326161 8.281600
min 5.000000e+02 5.000000e+02 0.000000e+00 5.310000e+00 4.930000e+00 0.000000e+00 -1.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 3.0 0.640000 3.0 0.000000 1.920000 55.730000 0.010000 44.210000 0.200000 0.000000
25% 8.000000e+03 8.000000e+03 7.825000e+03 9.750000e+00 2.484800e+02 4.576000e+04 1.178000e+01 0.000000e+00 0.000000e+00 16.000000 ... 3.0 53.725000 3.0 6.000000 147.780000 5101.920000 39.785000 2243.100000 45.000000 6.000000
50% 1.200000e+04 1.200000e+04 1.200000e+04 1.274000e+01 3.754300e+02 6.500000e+04 1.760000e+01 0.000000e+00 0.000000e+00 31.000000 ... 3.0 110.650000 3.0 15.000000 307.650000 9346.010000 121.350000 4200.000000 45.000000 14.000000
75% 2.000000e+04 2.000000e+04 2.000000e+04 1.599000e+01 5.799100e+02 9.000000e+04 2.403000e+01 0.000000e+00 1.000000e+00 50.000000 ... 3.0 204.660000 3.0 23.000000 572.130000 15361.420000 267.470000 6905.590000 50.000000 18.000000
max 4.000000e+04 4.000000e+04 4.000000e+04 3.099000e+01 1.719830e+03 1.099920e+07 9.990000e+02 3.900000e+01 3.300000e+01 226.000000 ... 3.0 943.940000 3.0 37.000000 2343.150000 39542.450000 1407.860000 33601.000000 521.350000 181.000000

8 rows × 106 columns

In [6]:
print("Revisión previa de las dimensiones", loan.shape)
Revisión previa de las dimensiones (1306387, 142)
In [7]:
loan.columns
Out[7]:
Index(['loan_amnt', 'funded_amnt', 'funded_amnt_inv', 'term', 'int_rate',
       'installment', 'grade', 'sub_grade', 'emp_title', 'emp_length',
       ...
       'hardship_payoff_balance_amount', 'hardship_last_payment_amount',
       'disbursement_method', 'debt_settlement_flag',
       'debt_settlement_flag_date', 'settlement_status', 'settlement_date',
       'settlement_amount', 'settlement_percentage', 'settlement_term'],
      dtype='object', length=142)

Variables Categóricas y Fechas

In [8]:
for col in loan.select_dtypes(include=['object']).columns:
    print ("Column {} has {} unique instances and NaN {}%".format( col, len(loan[col].unique()),round(loan[col].isna().sum()/len(loan)*100,2)) )
Column term has 2 unique instances and NaN 0.0%
Column grade has 7 unique instances and NaN 0.0%
Column sub_grade has 35 unique instances and NaN 0.0%
Column emp_title has 372942 unique instances and NaN 6.33%
Column emp_length has 12 unique instances and NaN 5.78%
Column home_ownership has 6 unique instances and NaN 0.0%
Column verification_status has 3 unique instances and NaN 0.0%
Column issue_d has 139 unique instances and NaN 0.0%
Column loan_status has 5 unique instances and NaN 0.0%
Column pymnt_plan has 1 unique instances and NaN 0.0%
Column desc has 124204 unique instances and NaN 90.37%
Column purpose has 14 unique instances and NaN 0.0%
Column title has 63149 unique instances and NaN 1.18%
Column zip_code has 946 unique instances and NaN 0.0%
Column addr_state has 51 unique instances and NaN 0.0%
Column earliest_cr_line has 739 unique instances and NaN 0.0%
Column initial_list_status has 2 unique instances and NaN 0.0%
Column last_pymnt_d has 136 unique instances and NaN 0.17%
Column next_pymnt_d has 101 unique instances and NaN 99.79%
Column last_credit_pull_d has 141 unique instances and NaN 0.0%
Column application_type has 2 unique instances and NaN 0.0%
Column verification_status_joint has 4 unique instances and NaN 98.23%
Column sec_app_earliest_cr_line has 561 unique instances and NaN 98.74%
Column hardship_flag has 2 unique instances and NaN 0.0%
Column hardship_type has 2 unique instances and NaN 99.59%
Column hardship_reason has 10 unique instances and NaN 99.59%
Column hardship_status has 4 unique instances and NaN 99.59%
Column hardship_start_date has 27 unique instances and NaN 99.59%
Column hardship_end_date has 25 unique instances and NaN 99.59%
Column payment_plan_start_date has 26 unique instances and NaN 99.59%
Column hardship_loan_status has 6 unique instances and NaN 99.59%
Column disbursement_method has 2 unique instances and NaN 0.0%
Column debt_settlement_flag has 2 unique instances and NaN 0.0%
Column debt_settlement_flag_date has 83 unique instances and NaN 97.55%
Column settlement_status has 4 unique instances and NaN 97.55%
Column settlement_date has 90 unique instances and NaN 97.55%

Variables Numéricas

In [9]:
for col in loan.select_dtypes(include=['number']).columns:
    print ("Column {}: Mean:{}, Min:{}, Max:{}, NaN: {}%".format( col,round(loan[col].mean(),2),round(loan[col].min(),2), round(loan[col].max(),2),round(loan[col].isna().sum()/len(loan)*100,2)) )
Column loan_amnt: Mean:14405.52, Min:500, Max:40000, NaN: 0.0%
Column funded_amnt: Mean:14396.43, Min:500, Max:40000, NaN: 0.0%
Column funded_amnt_inv: Mean:14368.1, Min:0.0, Max:40000.0, NaN: 0.0%
Column int_rate: Mean:13.26, Min:5.31, Max:30.99, NaN: 0.0%
Column installment: Mean:437.78, Min:4.93, Max:1719.83, NaN: 0.0%
Column annual_inc: Mean:76148.79, Min:0.0, Max:10999200.0, NaN: 0.0%
Column dti: Mean:18.25, Min:-1.0, Max:999.0, NaN: 0.02%
Column delinq_2yrs: Mean:0.32, Min:0.0, Max:39.0, NaN: 0.0%
Column inq_last_6mths: Mean:0.67, Min:0.0, Max:33.0, NaN: 0.0%
Column mths_since_last_delinq: Mean:34.3, Min:0.0, Max:226.0, NaN: 50.45%
Column mths_since_last_record: Mean:70.44, Min:0.0, Max:129.0, NaN: 82.96%
Column open_acc: Mean:11.59, Min:0.0, Max:90.0, NaN: 0.0%
Column pub_rec: Mean:0.22, Min:0.0, Max:86.0, NaN: 0.0%
Column revol_bal: Mean:16259.44, Min:0, Max:2904836, NaN: 0.0%
Column revol_util: Mean:51.91, Min:0.0, Max:892.3, NaN: 0.07%
Column total_acc: Mean:25.01, Min:1.0, Max:176.0, NaN: 0.0%
Column out_prncp: Mean:0.27, Min:0.0, Max:37138.1, NaN: 0.0%
Column out_prncp_inv: Mean:0.27, Min:0.0, Max:37138.1, NaN: 0.0%
Column total_pymnt: Mean:14778.94, Min:0.0, Max:63296.88, NaN: 0.0%
Column total_pymnt_inv: Mean:14749.64, Min:0.0, Max:63296.88, NaN: 0.0%
Column total_rec_prncp: Mean:12154.8, Min:0.0, Max:40000.0, NaN: 0.0%
Column total_rec_int: Mean:2387.11, Min:0.0, Max:28192.5, NaN: 0.0%
Column total_rec_late_fee: Mean:1.55, Min:-0.0, Max:1188.83, NaN: 0.0%
Column recoveries: Mean:235.47, Min:0.0, Max:39859.55, NaN: 0.0%
Column collection_recovery_fee: Mean:39.1, Min:0.0, Max:7174.72, NaN: 0.0%
Column last_pymnt_amnt: Mean:5459.7, Min:0.0, Max:42192.05, NaN: 0.0%
Column collections_12_mths_ex_med: Mean:0.02, Min:0.0, Max:20.0, NaN: 0.01%
Column mths_since_last_major_derog: Mean:43.69, Min:0.0, Max:226.0, NaN: 73.79%
Column policy_code: Mean:1.0, Min:1, Max:1, NaN: 0.0%
Column annual_inc_joint: Mean:117012.41, Min:11000.0, Max:1350000.0, NaN: 98.22%
Column dti_joint: Mean:18.88, Min:0.0, Max:69.49, NaN: 98.22%
Column acc_now_delinq: Mean:0.01, Min:0.0, Max:14.0, NaN: 0.0%
Column tot_coll_amt: Mean:249.43, Min:0.0, Max:9152545.0, NaN: 5.38%
Column tot_cur_bal: Mean:141079.6, Min:0.0, Max:8000078.0, NaN: 5.38%
Column open_acc_6m: Mean:1.06, Min:0.0, Max:18.0, NaN: 61.76%
Column open_act_il: Mean:2.8, Min:0.0, Max:57.0, NaN: 61.76%
Column open_il_12m: Mean:0.78, Min:0.0, Max:25.0, NaN: 61.76%
Column open_il_24m: Mean:1.76, Min:0.0, Max:51.0, NaN: 61.76%
Column mths_since_rcnt_il: Mean:19.42, Min:0.0, Max:511.0, NaN: 62.75%
Column total_bal_il: Mean:35982.15, Min:0.0, Max:1711009.0, NaN: 61.76%
Column il_util: Mean:71.54, Min:0.0, Max:558.0, NaN: 66.88%
Column open_rv_12m: Mean:1.43, Min:0.0, Max:28.0, NaN: 61.76%
Column open_rv_24m: Mean:3.02, Min:0.0, Max:53.0, NaN: 61.76%
Column max_bal_bc: Mean:5527.69, Min:0.0, Max:776843.0, NaN: 61.76%
Column all_util: Mean:58.23, Min:0.0, Max:198.0, NaN: 61.76%
Column total_rev_hi_lim: Mean:32707.97, Min:0.0, Max:9999999.0, NaN: 5.38%
Column inq_fi: Mean:1.1, Min:0.0, Max:48.0, NaN: 61.76%
Column total_cu_tl: Mean:1.62, Min:0.0, Max:79.0, NaN: 61.76%
Column inq_last_12m: Mean:2.33, Min:0.0, Max:67.0, NaN: 61.76%
Column acc_open_past_24mths: Mean:4.7, Min:0.0, Max:64.0, NaN: 3.83%
Column avg_cur_bal: Mean:13487.68, Min:0.0, Max:958084.0, NaN: 5.38%
Column bc_open_to_buy: Mean:10125.2, Min:0.0, Max:559912.0, NaN: 4.85%
Column bc_util: Mean:60.07, Min:0.0, Max:339.6, NaN: 4.91%
Column chargeoff_within_12_mths: Mean:0.01, Min:0.0, Max:10.0, NaN: 0.01%
Column delinq_amnt: Mean:15.03, Min:0.0, Max:249925.0, NaN: 0.0%
Column mo_sin_old_il_acct: Mean:125.84, Min:0.0, Max:999.0, NaN: 8.19%
Column mo_sin_old_rev_tl_op: Mean:181.5, Min:2.0, Max:852.0, NaN: 5.38%
Column mo_sin_rcnt_rev_tl_op: Mean:13.09, Min:0.0, Max:438.0, NaN: 5.38%
Column mo_sin_rcnt_tl: Mean:7.84, Min:0.0, Max:314.0, NaN: 5.38%
Column mort_acc: Mean:1.68, Min:0.0, Max:51.0, NaN: 3.83%
Column mths_since_recent_bc: Mean:23.79, Min:0.0, Max:639.0, NaN: 4.78%
Column mths_since_recent_bc_dlq: Mean:39.69, Min:0.0, Max:202.0, NaN: 76.33%
Column mths_since_recent_inq: Mean:6.7, Min:0.0, Max:25.0, NaN: 13.19%
Column mths_since_recent_revol_delinq: Mean:35.83, Min:0.0, Max:202.0, NaN: 66.64%
Column num_accts_ever_120_pd: Mean:0.51, Min:0.0, Max:51.0, NaN: 5.38%
Column num_actv_bc_tl: Mean:3.64, Min:0.0, Max:35.0, NaN: 5.38%
Column num_actv_rev_tl: Mean:5.65, Min:0.0, Max:63.0, NaN: 5.38%
Column num_bc_sats: Mean:4.73, Min:0.0, Max:63.0, NaN: 4.48%
Column num_bc_tl: Mean:8.12, Min:0.0, Max:70.0, NaN: 5.38%
Column num_il_tl: Mean:8.57, Min:0.0, Max:159.0, NaN: 5.38%
Column num_op_rev_tl: Mean:8.28, Min:0.0, Max:83.0, NaN: 5.38%
Column num_rev_accts: Mean:14.64, Min:0.0, Max:128.0, NaN: 5.38%
Column num_rev_tl_bal_gt_0: Mean:5.6, Min:0.0, Max:45.0, NaN: 5.38%
Column num_sats: Mean:11.64, Min:0.0, Max:90.0, NaN: 4.48%
Column num_tl_120dpd_2m: Mean:0.0, Min:0.0, Max:6.0, NaN: 9.06%
Column num_tl_30dpd: Mean:0.0, Min:0.0, Max:4.0, NaN: 5.38%
Column num_tl_90g_dpd_24m: Mean:0.09, Min:0.0, Max:39.0, NaN: 5.38%
Column num_tl_op_past_12m: Mean:2.18, Min:0.0, Max:32.0, NaN: 5.38%
Column pct_tl_nvr_dlq: Mean:94.17, Min:0.0, Max:100.0, NaN: 5.39%
Column percent_bc_gt_75: Mean:45.32, Min:0.0, Max:100.0, NaN: 4.88%
Column pub_rec_bankruptcies: Mean:0.13, Min:0.0, Max:12.0, NaN: 0.1%
Column tax_liens: Mean:0.05, Min:0.0, Max:85.0, NaN: 0.01%
Column tot_hi_cred_lim: Mean:174211.06, Min:0.0, Max:9999999.0, NaN: 5.38%
Column total_bal_ex_mort: Mean:49614.18, Min:0.0, Max:3408095.0, NaN: 3.83%
Column total_bc_limit: Mean:21566.24, Min:0.0, Max:1105500.0, NaN: 3.83%
Column total_il_high_credit_limit: Mean:42067.17, Min:0.0, Max:2101913.0, NaN: 5.38%
Column revol_bal_joint: Mean:31352.4, Min:0.0, Max:357135.0, NaN: 98.74%
Column sec_app_inq_last_6mths: Mean:0.76, Min:0.0, Max:6.0, NaN: 98.74%
Column sec_app_mort_acc: Mean:1.67, Min:0.0, Max:18.0, NaN: 98.74%
Column sec_app_open_acc: Mean:11.31, Min:0.0, Max:82.0, NaN: 98.74%
Column sec_app_revol_util: Mean:57.35, Min:0.0, Max:212.6, NaN: 98.76%
Column sec_app_open_act_il: Mean:2.95, Min:0.0, Max:38.0, NaN: 98.74%
Column sec_app_num_rev_accts: Mean:12.82, Min:0.0, Max:92.0, NaN: 98.74%
Column sec_app_chargeoff_within_12_mths: Mean:0.06, Min:0.0, Max:20.0, NaN: 98.74%
Column sec_app_collections_12_mths_ex_med: Mean:0.09, Min:0.0, Max:16.0, NaN: 98.74%
Column sec_app_mths_since_last_major_derog: Mean:36.34, Min:0.0, Max:132.0, NaN: 99.55%
Column deferral_term: Mean:3.0, Min:3.0, Max:3.0, NaN: 99.59%
Column hardship_amount: Mean:148.21, Min:0.64, Max:943.94, NaN: 99.59%
Column hardship_length: Mean:3.0, Min:3.0, Max:3.0, NaN: 99.59%
Column hardship_dpd: Mean:13.97, Min:0.0, Max:37.0, NaN: 99.59%
Column orig_projected_additional_accrued_interest: Mean:414.08, Min:1.92, Max:2343.15, NaN: 99.74%
Column hardship_payoff_balance_amount: Mean:11028.73, Min:55.73, Max:39542.45, NaN: 99.59%
Column hardship_last_payment_amount: Mean:184.58, Min:0.01, Max:1407.86, NaN: 99.59%
Column settlement_amount: Mean:5051.68, Min:44.21, Max:33601.0, NaN: 97.55%
Column settlement_percentage: Mean:47.67, Min:0.2, Max:521.35, NaN: 97.55%
Column settlement_term: Mean:13.09, Min:0.0, Max:181.0, NaN: 97.55%

Análisis Exploratorio (EDA)

Target Variable

In [10]:
plt.figure(figsize = (14,6))
plt.style.use("seaborn-pastel")
g = sns.countplot(x="loan_status", data=loan)
g.set_xticklabels(g.get_xticklabels(),rotation=45)
g.set_xlabel("Loan Status", fontsize=12)
g.set_ylabel("Cantidad", fontsize=15)
g.set_title("Distribucion del Estado de Préstamo", fontsize=20)
sizes=[]
for p in g.patches:
    height = p.get_height()
    sizes.append(height)
    g.text(p.get_x()+p.get_width()/2.,
            height + 3,
            '{:1.2f}%'.format(height/len(loan)*100),
            ha="center", fontsize=12) 
g.set_ylim(0, max(sizes) * 1.10)

plt.show()
In [11]:
def calc_risk(data):
    status = data['loan_status']
    if (status == 'Fully Paid' or status == 'Does not meet the credit policy. Status:Fully Paid'):
        return "No Default"
    return "Default"
loan['credit_risk'] = loan.apply(calc_risk, axis=1)
In [12]:
plt.figure(figsize = (14,6))
plt.style.use('seaborn-pastel')
g = sns.countplot(x="credit_risk", data=loan)
g.set_xticklabels(g.get_xticklabels(),rotation=45)
g.set_xlabel("Credit Risk", fontsize=12)
g.set_ylabel("Cantidad", fontsize=15)
g.set_title("Distribucion del Riesgo Crediticio", fontsize=20)
sizes=[]
for p in g.patches:
    height = p.get_height()
    sizes.append(height)
    g.text(p.get_x()+p.get_width()/2.,
            height + 3,
            '{:1.2f}%'.format(height/len(loan)*100),
            ha="center", fontsize=12) 
g.set_ylim(0, max(sizes) * 1.10)

plt.show()

Variables Independientes

Las variables explicativas las agruparemos por tipo de información que entregan para un análisis detallado, es así que se tendrán los siguientes grupos:

  • Caracteristicas del Préstamo
  • Caracteristicas del Prestatario
  • Evaluación del Prestatario
  • Historial Crediticio del Prestatario
  • Caracteristicas Financieras Actuales
  • Rendimiento del Préstamo
  • Endeudamiento del prestatario
In [13]:
def plot_var(col_name, full_name, continuous):
    
    fig, (ax1, ax2) = plt.subplots(1, 2, sharex=False, figsize=(15,3))
    # Plot 1
    plt.style.use('seaborn-pastel')
    if continuous:  
        sns.distplot(loan.loc[loan[col_name].notnull(), col_name], kde=False, ax=ax1)
    else:
        sns.countplot(loan[col_name], order=sorted(loan[col_name].unique()), color='#5975A4', saturation=1, ax=ax1)
    ax1.set_xlabel(full_name)
    ax1.set_ylabel('Count')
    ax1.set_title(full_name)

          
    #  Plot 2
    if continuous:
        sns.boxplot(x=col_name, y='credit_risk', data=loan, ax=ax2)
        ax2.set_ylabel('')
        ax2.set_title(full_name + ' por Riesgo Crediticio')
    else:
        Default_rates = loan.groupby(col_name)['credit_risk'].value_counts(normalize=True)[:,'Default']
        sns.barplot(x=Default_rates.index, y=Default_rates.values, color='#5975A4', saturation=1, ax=ax2)
        ax2.set_ylabel('Proporción de Préstamos Default')
        ax2.set_title('Default por ' + full_name)
        ax2.set_xlabel(full_name)
    
    # Plot 3
    if continuous:  
        facet = sns.FacetGrid(loan, hue = 'credit_risk', size=3, aspect=4)
        facet.map(sns.kdeplot, col_name, shade=True)
        
        facet.add_legend()  
    else:
        fig = plt.figure(figsize=(12,3))
        sns.countplot(x=col_name, hue='credit_risk', data=loan, order=sorted(loan[col_name].unique()) )
     
    plt.tight_layout()
In [14]:
def matrix_corr(df, mirror):
    plt.style.use('seaborn-pastel')
    
    corr = df.corr(method='pearson')
    
    fig, ax = plt.subplots(figsize=(10, 10))
    
    colormap = sns.diverging_palette(10,220, as_cmap=True)
    if mirror == True:
      
      sns.heatmap(corr, cmap="coolwarm", annot=True, fmt=".2f")
      
      plt.xticks(range(len(corr.columns)), corr.columns);
     
      plt.yticks(range(len(corr.columns)), corr.columns)
    else:
        
        dropSelf = np.zeros_like(corr)
        dropSelf[np.triu_indices_from(dropSelf)] = True
        
        colormap = sns.diverging_palette(220, 10, as_cmap=True)
        
        sns.heatmap(corr, cmap="coolwarm", annot=True, fmt=".2f", mask=dropSelf)
       
        plt.xticks(range(len(corr.columns)), corr.columns);
      
        plt.yticks(range(len(corr.columns)), corr.columns)
   
    plt.show()

Secondary Applicant

Se decide prescindir de todas las observaciones en las que haya un secondary applicant. Tomamos esta decisión con el objetivo de crear un modelo que sea capaz de hacer una predicción lo más precisa posible, y entendemos que la información asimétrica entre los préstamos con y sin secondary applicant podría distorsionar nuestro modelo.

Eliminamos, por tanto, las observaciones con "Joint App" y las columnas que recogen la información referente a este tipo de créditos.

In [15]:
loan.drop(['annual_inc_joint','dti_joint','verification_status_joint',
           'revol_bal_joint','sec_app_earliest_cr_line',
           'sec_app_inq_last_6mths','sec_app_mort_acc',
           'sec_app_open_acc','sec_app_revol_util',
           'sec_app_open_act_il','sec_app_num_rev_accts',
           'sec_app_chargeoff_within_12_mths',
           'sec_app_collections_12_mths_ex_med',
           'sec_app_mths_since_last_major_derog'], 
          axis = 1, inplace = True)
Application Type
In [16]:
loan['application_type'].value_counts()
Out[16]:
Individual    1283143
Joint App       23244
Name: application_type, dtype: int64
In [17]:
plot_var('application_type', 'Application Type', continuous=False)

Nuesto modelo sólo considerará préstamos individuales, es así que quitaremos lo préstamos compartidos (Joint App).

In [18]:
loan = loan[loan.application_type == 'Individual']
In [19]:
loan.drop(['application_type'],1, inplace=True)
loan.shape
Out[19]:
(1283143, 128)
Tax Liens

Cuando el propietario de un bien, deja de pagar los impuestos correspondientes sobre este, el condado o la ciudad donde se encuentra este bien puede colocar un embargo sobre este bien en propiedad (lien). Por tanto este lien o gravamen es un reclamo legal hacia la propiedad que no ha pagado sus impuestos por el monto adeudado.

In [20]:
loan['tax_liens'].isnull().sum()
Out[20]:
105
In [21]:
loan['tax_liens'].fillna(0, inplace = True)
In [22]:
plot_var('tax_liens', 'Tax liens', continuous=False)

Caracteristicas del Préstamo

En este apartado se agruparan las variables que hacen referencia al préstamo. Estas variables son:

  • 'Loan Amount',The listed amount of the loan applied for by the borrower. If at some point in time, the credit department reduces the loan amount, then it will be reflected in this value.
  • 'Funded Amount', The total amount committed to that loan at that point in time.
  • 'Funded Amount Inv',The total amount committed by investors for that loan at that point in time.
  • 'Term', The number of payments on the loan. Values are in months and can be either 36 or 60.
  • 'Installment',The monthly payment owed by the borrower if the loan originates.
  • 'Issue Date',The month which the loan was funded.
  • 'Payment Plan',Indicates if a payment plan has been put in place for the loan.
  • 'Desc',Loan description provided by the borrower.
  • 'Purpose',A category provided by the borrower for the loan request.
  • 'Title',The loan title provided by the borrower.
  • 'Earliest CR Line',The month the borrower's earliest reported credit line was opened.
  • 'Initial List Status', The initial listing status of the loan. Possible values are – W, F.
  • 'Policy Code', publicly available policy_code=1, new products not publicly available policy_code=2.
  • 'Application Type', Indicates whether the loan is an individual application or a joint application with two co-borrowers.
In [23]:
matrix_corr(loan[['loan_amnt','funded_amnt','funded_amnt_inv','installment']], mirror=False)
Loan Amount

El monto listado del préstamo solicitado por el prestatario. Si en algún momento, el departamento de crédito reduce el monto del préstamo, entonces se reflejará en este valor.

In [24]:
plot_var('loan_amnt', 'Loan Amount', continuous=True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

No hay valores ausentes en Loan_Amnt. Se realizará rangos del monto de préstamo dado que se visualiza ciertos valores que tienen frecuencia similar.

In [25]:
round(loan["loan_amnt"].isna().sum()/len(loan)*100,2)
Out[25]:
0.0
In [26]:
purp_loan= ['loan_amnt', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[26]:
credit_risk Default No Default
loan_amnt
500 0 0
550 0 0
600 0 0
700 0 0
725 0 0
750 0 0
800 0 0
850 0 0
900 0 0
925 0 0
950 0 0
1000 0.28 0.46
1025 0 0
1050 0 0
1075 0 0
1100 0.01 0.01
1125 0 0
1150 0 0
1175 0 0
1200 0.11 0.19
1225 0 0
1250 0 0.01
1275 0 0
1300 0.01 0.02
1325 0 0
1350 0 0
1375 0 0
1400 0.04 0.07
1425 0 0
1450 0.01 0.02
1475 0 0
1500 0.17 0.3
1525 0 0
1550 0 0.01
1575 0 0
1600 0.07 0.12
1625 0 0
1650 0 0
1675 0.01 0.01
1700 0.01 0.02
1725 0 0
1750 0.01 0.01
1775 0 0
1800 0.08 0.14
1825 0 0
1850 0 0
1875 0.01 0
1900 0.01 0.01
1925 0.01 0.01
1950 0.01 0.01
1975 0 0
2000 0.55 0.76
2025 0 0
2050 0.01 0.01
2075 0 0.01
2100 0.05 0.07
2125 0.01 0.01
2150 0.01 0.01
2175 0 0
2200 0.07 0.08
2225 0.01 0
2250 0.01 0.02
2275 0.01 0.01
2300 0.01 0.03
2325 0.01 0
2350 0.01 0.01
2375 0.01 0.01
2400 0.23 0.31
2425 0.01 0.01
2450 0 0.01
2475 0 0
2500 0.3 0.48
2525 0.01 0.01
2550 0.01 0.01
2575 0.01 0.01
2600 0.03 0.04
2625 0.01 0.01
2650 0.02 0.02
2675 0 0.01
2700 0.03 0.05
2725 0.01 0.01
2750 0.02 0.02
2775 0.01 0.01
2800 0.12 0.16
2825 0.01 0.01
2850 0.01 0.01
2875 0.02 0.02
2900 0.01 0.02
2925 0.01 0.01
2950 0.01 0.01
2975 0.01 0.01
3000 1.01 1.39
3025 0.04 0.05
3050 0.02 0.01
3075 0.01 0.01
3100 0.01 0.02
3125 0.02 0.02
3150 0.01 0.01
3175 0.01 0.01
3200 0.14 0.22
3225 0.01 0.01
3250 0.05 0.04
3275 0.01 0.01
3300 0.02 0.04
3325 0.01 0.01
3350 0.02 0.02
3375 0.01 0.01
3400 0.02 0.03
3425 0.01 0.01
3450 0.01 0.01
3475 0.01 0.01
3500 0.32 0.52
3525 0.01 0.01
3550 0.02 0.01
3575 0.01 0.01
3600 0.36 0.45
3625 0.02 0.03
3650 0.01 0.01
3675 0.01 0.01
3700 0.02 0.03
3725 0.01 0.01
3750 0.02 0.02
3775 0.01 0.01
3800 0.02 0.04
3825 0.02 0.02
3850 0.02 0.02
3875 0.01 0.01
3900 0.03 0.04
3925 0.01 0.01
3950 0.02 0.02
3975 0.02 0.02
4000 1.09 1.5
4025 0.01 0.01
4050 0.01 0.01
4075 0.02 0.01
4100 0.02 0.02
4125 0.02 0.02
4150 0.02 0.01
4175 0.01 0.01
4200 0.25 0.3
4225 0.02 0.01
4250 0.03 0.02
4275 0.01 0.01
4300 0.03 0.04
4325 0.02 0.02
4350 0.02 0.02
4375 0.03 0.03
4400 0.03 0.06
4425 0.01 0.01
4450 0.02 0.03
4475 0.02 0.02
4500 0.24 0.35
4525 0.02 0.01
4550 0.02 0.02
4575 0.02 0.01
4600 0.03 0.04
4625 0.02 0.02
4650 0.02 0.01
4675 0.02 0.02
4700 0.02 0.03
4725 0.02 0.02
4750 0.06 0.05
4775 0.02 0.01
4800 0.49 0.62
4825 0.02 0.01
4850 0.02 0.02
4875 0.02 0.02
4900 0.03 0.05
4925 0.01 0.01
4950 0.04 0.04
4975 0.01 0.01
5000 3.04 3.79
5025 0.02 0.01
5050 0.02 0.03
5075 0.02 0.02
5100 0.04 0.04
5125 0.03 0.02
5150 0.02 0.02
5175 0.02 0.02
5200 0.07 0.11
5225 0.02 0.02
5250 0.03 0.03
5275 0.02 0.02
5300 0.03 0.05
5325 0.02 0.02
5350 0.01 0.01
5375 0.06 0.06
5400 0.11 0.16
5425 0.01 0.01
5450 0.02 0.02
5475 0.01 0.01
5500 0.26 0.42
5525 0.02 0.02
5550 0.02 0.02
5575 0.02 0.01
5600 0.31 0.42
5625 0.01 0.01
5650 0.02 0.02
5675 0.02 0.01
5700 0.04 0.05
5725 0.02 0.02
5750 0.04 0.04
5775 0.01 0.01
5800 0.04 0.05
5825 0.02 0.02
5850 0.02 0.02
5875 0.03 0.03
5900 0.02 0.02
5925 0.02 0.01
5950 0.04 0.03
5975 0.03 0.02
6000 2.48 3.57
6025 0.14 0.12
6050 0.02 0.02
6075 0.06 0.05
6100 0.04 0.03
6125 0.02 0.01
6150 0.03 0.02
6175 0.01 0.01
6200 0.04 0.06
6225 0.02 0.02
6250 0.07 0.07
6275 0.01 0.01
6300 0.06 0.07
6325 0.03 0.02
6350 0.04 0.03
6375 0.02 0.02
6400 0.32 0.39
6425 0.02 0.01
6450 0.02 0.02
6475 0.03 0.02
6500 0.29 0.51
6525 0.01 0.01
6550 0.01 0.01
6575 0.02 0.01
6600 0.1 0.13
6625 0.04 0.04
6650 0.02 0.02
6675 0.01 0.01
6700 0.04 0.05
6725 0.03 0.02
6750 0.02 0.02
6775 0.02 0.01
6800 0.06 0.09
6825 0.02 0.02
6850 0.03 0.03
6875 0.01 0.01
6900 0.03 0.03
6925 0.02 0.02
6950 0.02 0.02
6975 0.01 0.01
7000 1.35 1.89
7025 0.02 0.02
7050 0.02 0.02
7075 0.02 0.02
7100 0.03 0.03
7125 0.06 0.05
7150 0.03 0.02
7175 0.02 0.01
7200 0.65 0.81
7225 0.03 0.02
7250 0.03 0.03
7275 0.02 0.02
7300 0.03 0.04
7325 0.02 0.01
7350 0.04 0.03
7375 0.03 0.02
7400 0.03 0.04
7425 0.02 0.01
7450 0.03 0.02
7475 0.05 0.03
7500 0.49 0.72
7525 0.02 0.01
7550 0.05 0.04
7575 0.02 0.02
7600 0.03 0.05
7625 0.02 0.02
7650 0.02 0.02
7675 0.03 0.02
7700 0.05 0.06
7725 0.01 0.01
7750 0.06 0.05
7775 0.02 0.01
7800 0.15 0.18
7825 0.02 0.01
7850 0.02 0.02
7875 0.03 0.02
7900 0.05 0.04
7925 0.03 0.03
7950 0.02 0.01
7975 0.03 0.02
8000 2.87 3.7
8025 0.01 0.01
8050 0.03 0.02
8075 0.02 0.01
8100 0.02 0.03
8125 0.03 0.03
8150 0.02 0.02
8175 0.01 0.01
8200 0.04 0.05
8225 0.02 0.02
8250 0.03 0.02
8275 0.03 0.02
8300 0.03 0.03
8325 0.06 0.06
8350 0.02 0.02
8375 0.02 0.01
8400 0.47 0.56
8425 0.02 0.01
8450 0.03 0.03
8475 0.03 0.02
8500 0.28 0.42
8525 0.01 0.01
8550 0.02 0.01
8575 0.03 0.03
8600 0.03 0.05
8625 0.03 0.02
8650 0.02 0.02
8675 0.02 0.02
8700 0.03 0.04
8725 0.03 0.03
8750 0.04 0.04
8775 0.02 0.01
8800 0.09 0.12
8825 0.02 0.01
8850 0.02 0.01
8875 0.09 0.08
8900 0.01 0.02
8925 0.01 0.01
8950 0.04 0.03
8975 0.04 0.03
9000 0.92 1.42
9025 0.03 0.01
9050 0.02 0.02
9075 0.02 0.01
9100 0.08 0.07
9125 0.03 0.02
9150 0.03 0.01
9175 0.04 0.03
9200 0.04 0.05
9225 0.02 0.02
9250 0.05 0.05
9275 0.02 0.01
9300 0.03 0.03
9325 0.04 0.03
9350 0.04 0.03
9375 0.02 0.01
9400 0.03 0.03
9425 0.01 0.01
9450 0.07 0.06
9475 0.02 0.01
9500 0.15 0.23
9525 0.02 0.02
9550 0.03 0.02
9575 0.02 0.01
9600 0.71 0.9
9625 0.02 0.01
9650 0.03 0.02
9675 0.02 0.01
9700 0.04 0.03
9725 0.02 0.02
9750 0.08 0.07
9775 0.02 0.01
9800 0.12 0.14
9825 0.02 0.01
9850 0.03 0.02
9875 0.03 0.02
9900 0.04 0.04
9925 0.02 0.03
9950 0.04 0.03
9975 0.03 0.03
10000 6.88 7.53
10025 0.02 0.01
10050 0.04 0.03
10075 0.07 0.04
10100 0.03 0.02
10125 0.02 0.01
10150 0.02 0.02
10175 0.01 0.01
10200 0.16 0.13
10225 0.02 0.01
10250 0.03 0.02
10275 0.01 0.01
10300 0.03 0.03
10325 0.03 0.02
10350 0.02 0.02
10375 0.03 0.03
10400 0.17 0.17
10425 0.03 0.02
10450 0.02 0.02
10475 0.03 0.02
10500 0.32 0.3
10525 0.03 0.02
10550 0.04 0.03
10575 0.04 0.03
10600 0.03 0.03
10625 0.09 0.06
10650 0.03 0.02
10675 0.02 0.01
10700 0.02 0.02
10725 0.03 0.02
10750 0.07 0.05
10775 0.02 0.02
10800 0.31 0.28
10825 0.02 0.01
10850 0.05 0.03
10875 0.03 0.02
10900 0.02 0.02
10925 0.02 0.02
10950 0.03 0.02
10975 0.05 0.02
11000 0.62 0.88
11025 0.02 0.01
11050 0.03 0.02
11075 0.03 0.02
11100 0.07 0.05
11125 0.02 0.01
11150 0.03 0.02
11175 0.02 0.02
11200 0.66 0.45
11225 0.03 0.01
11250 0.04 0.02
11275 0.01 0.01
11300 0.03 0.03
11325 0.05 0.03
11350 0.02 0.01
11375 0.02 0.01
11400 0.09 0.07
11425 0.02 0.01
11450 0.02 0.01
11475 0.02 0.01
11500 0.22 0.24
11525 0.03 0.02
11550 0.03 0.02
11575 0.02 0.01
11600 0.04 0.03
11625 0.04 0.03
11650 0.02 0.02
11675 0.02 0.02
11700 0.07 0.05
11725 0.02 0.01
11750 0.04 0.02
11775 0.02 0.01
11800 0.02 0.02
11825 0.01 0.01
11850 0.05 0.03
11875 0.06 0.03
11900 0.05 0.03
11925 0.02 0.01
11950 0.04 0.03
11975 0.05 0.03
12000 5.04 5.53
12025 0.01 0.01
12050 0.03 0.02
12075 0.04 0.02
12100 0.02 0.02
12125 0.02 0.01
12150 0.04 0.02
12175 0.05 0.04
12200 0.02 0.02
12225 0.04 0.01
12250 0.07 0.05
12275 0.02 0.01
12300 0.05 0.04
12325 0.02 0.01
12350 0.02 0.01
12375 0.05 0.05
12400 0.03 0.03
12425 0.02 0.01
12450 0.03 0.02
12475 0.02 0.01
12500 0.21 0.26
12525 0.02 0.01
12550 0.03 0.01
12575 0.03 0.02
12600 0.19 0.13
12625 0.02 0.01
12650 0.02 0.01
12675 0.02 0.01
12700 0.03 0.03
12725 0.03 0.02
12750 0.03 0.02
12775 0.01 0.01
12800 0.3 0.25
12825 0.02 0.01
12850 0.02 0.01
12875 0.03 0.02
12900 0.02 0.02
12925 0.02 0.01
12950 0.05 0.03
12975 0.02 0.01
13000 0.62 0.88
13025 0.02 0.01
13050 0.02 0.01
13075 0.01 0.01
13100 0.03 0.02
13125 0.01 0.01
13150 0.04 0.02
13175 0.02 0.01
13200 0.2 0.18
13225 0.03 0.02
13250 0.07 0.04
13275 0.02 0.01
13300 0.04 0.03
13325 0.02 0.01
13350 0.02 0.01
13375 0.03 0.02
13400 0.02 0.02
13425 0.03 0.01
13450 0.02 0.01
13475 0.06 0.03
13500 0.14 0.18
13525 0.01 0.01
13550 0.02 0.01
13575 0.02 0.01
13600 0.12 0.09
13625 0.03 0.02
13650 0.02 0.02
13675 0.03 0.02
13700 0.03 0.03
13725 0.02 0.01
13750 0.05 0.03
13775 0.01 0.01
13800 0.06 0.06
13825 0.02 0.01
13850 0.03 0.01
13875 0.01 0.01
13900 0.02 0.02
13925 0.03 0.02
13950 0.02 0.01
13975 0.02 0.01
14000 1.44 1.52
14025 0.03 0.02
14050 0.03 0.01
14075 0.06 0.03
14100 0.03 0.02
14125 0.04 0.04
14150 0.02 0.01
14175 0.02 0.01
14200 0.02 0.02
14225 0.02 0.01
14250 0.03 0.02
14275 0.02 0.01
14300 0.04 0.04
14325 0.02 0.01
14350 0.04 0.02
14375 0.05 0.03
14400 0.66 0.61
14425 0.02 0.01
14450 0.02 0.01
14475 0.02 0.01
14500 0.1 0.12
14525 0.01 0.01
14550 0.02 0.01
14575 0.03 0.02
14600 0.04 0.03
14625 0.01 0.01
14650 0.01 0.01
14675 0.05 0.03
14700 0.09 0.05
14725 0.02 0.01
14750 0.03 0.02
14775 0.02 0.01
14800 0.04 0.03
14825 0.05 0.03
14850 0.02 0.01
14875 0.02 0.01
14900 0.04 0.02
14925 0.02 0.01
14950 0.03 0.02
14975 0.06 0.03
15000 5.06 5.24
15025 0.01 0.01
15050 0.02 0.02
15075 0.02 0.01
15100 0.04 0.02
15125 0.04 0.02
15150 0.01 0.01
15175 0.02 0.01
15200 0.07 0.05
15225 0.02 0.01
15250 0.06 0.04
15275 0.02 0.01
15300 0.03 0.02
15325 0.02 0.01
15350 0.04 0.03
15375 0.01 0.01
15400 0.08 0.06
15425 0.02 0.01
15450 0.03 0.02
15475 0.02 0.01
15500 0.09 0.1
15525 0.01 0.01
15550 0.03 0.02
15575 0.01 0.01
15600 0.16 0.16
15625 0.03 0.02
15650 0.01 0.01
15675 0.01 0.01
15700 0.02 0.01
15725 0.01 0.01
15750 0.03 0.02
15775 0.02 0.01
15800 0.03 0.02
15825 0.04 0.02
15850 0.06 0.04
15875 0.05 0.02
15900 0.02 0.02
15925 0.02 0.01
15950 0.05 0.02
15975 0.02 0.01
16000 2.9 2.65
16025 0.01 0.01
16050 0.01 0.01
16075 0.01 0.01
16100 0.04 0.03
16125 0.01 0.01
16150 0.04 0.02
16175 0.01 0.01
16200 0.09 0.05
16225 0.02 0.01
16250 0.01 0.01
16275 0.02 0.01
16300 0.04 0.02
16325 0.02 0.01
16350 0.01 0.01
16375 0.03 0.01
16400 0.02 0.01
16425 0.04 0.03
16450 0.05 0.03
16475 0.02 0.01
16500 0.11 0.13
16525 0.02 0.01
16550 0.04 0.02
16575 0.02 0.01
16600 0.02 0.01
16625 0.02 0.01
16650 0.02 0.01
16675 0.02 0.01
16700 0.05 0.02
16725 0.01 0.01
16750 0.07 0.04
16775 0.02 0.01
16800 0.34 0.28
16825 0.02 0.01
16850 0.01 0.01
16875 0.01 0.01
16900 0.03 0.02
16925 0.01 0.01
16950 0.05 0.03
16975 0.02 0.01
17000 0.53 0.64
17025 0.01 0.01
17050 0.05 0.03
17075 0.01 0.01
17100 0.05 0.02
17125 0.03 0.01
17150 0.02 0.01
17175 0.01 0.01
17200 0.04 0.02
17225 0.02 0.01
17250 0.02 0.01
17275 0.04 0.02
17300 0.01 0.01
17325 0.03 0.02
17350 0.03 0.01
17375 0.01 0.01
17400 0.03 0.02
17425 0.02 0.01
17450 0.02 0.01
17475 0.05 0.03
17500 0.2 0.19
17525 0.01 0.01
17550 0.03 0.01
17575 0.01 0.01
17600 0.15 0.12
17625 0.07 0.04
17650 0.01 0.01
17675 0.02 0.01
17700 0.02 0.01
17725 0.01 0
17750 0.02 0.01
17775 0.02 0.01
17800 0.02 0.01
17825 0.01 0.01
17850 0.02 0.01
17875 0.03 0.02
17900 0.01 0.01
17925 0.02 0.01
17950 0.02 0.01
17975 0.04 0.02
18000 2.36 2.25
18025 0.02 0.01
18050 0.02 0.01
18075 0.03 0.02
18100 0.01 0.01
18125 0.02 0.01
18150 0.03 0.02
18175 0.01 0.01
18200 0.06 0.05
18225 0.07 0.04
18250 0.05 0.03
18275 0.02 0.01
18300 0.02 0.02
18325 0.01 0.01
18350 0.04 0.02
18375 0.02 0.01
18400 0.07 0.05
18425 0.02 0.01
18450 0.04 0.02
18475 0.04 0.01
18500 0.08 0.09
18525 0.01 0.01
18550 0.04 0.02
18575 0.01 0.01
18600 0.03 0.03
18625 0.02 0.01
18650 0.01 0.01
18675 0.02 0.01
18700 0.03 0.02
18725 0.03 0.01
18750 0.02 0.01
18775 0.02 0.01
18800 0.02 0.02
18825 0.06 0.04
18850 0.01 0.01
18875 0.01 0.01
18900 0.08 0.04
18925 0.01 0
18950 0.03 0.01
18975 0.01 0.01
19000 0.27 0.3
19025 0.01 0.01
19050 0.02 0.01
19075 0.04 0.03
19100 0.02 0.01
19125 0.04 0.02
19150 0.03 0.01
19175 0.01 0.01
19200 0.43 0.35
19225 0.02 0.01
19250 0.02 0.01
19275 0.01 0.01
19300 0.04 0.02
19325 0.01 0.01
19350 0.04 0.02
19375 0.02 0.01
19400 0.02 0.02
19425 0.04 0.02
19450 0.01 0.01
19475 0.02 0.01
19500 0.07 0.08
19525 0.01 0
19550 0.01 0.01
19575 0.02 0.01
19600 0.08 0.06
19625 0.01 0.01
19650 0.02 0.01
19675 0.02 0.01
19700 0.02 0.01
19725 0.02 0.01
19750 0.1 0.05
19775 0.02 0.01
19800 0.11 0.06
19825 0.01 0.01
19850 0.01 0.01
19875 0.02 0.01
19900 0.01 0.01
19925 0.01 0.01
19950 0.04 0.02
19975 0.01 0.01
20000 5.43 5.12
20025 0.01 0
20050 0.04 0.03
20075 0.01 0
20100 0.01 0.01
20125 0.05 0.03
20150 0.04 0.02
20175 0.01 0.01
20200 0.02 0.01
20225 0.02 0.02
20250 0.02 0.01
20275 0.02 0.01
20300 0.01 0.01
20325 0.01 0.01
20350 0.01 0.01
20375 0.02 0.01
20400 0.12 0.1
20425 0.01 0.01
20450 0.01 0.01
20475 0.02 0.01
20500 0.07 0.05
20525 0.01 0.01
20550 0.01 0.01
20575 0.02 0.01
20600 0.01 0.01
20625 0.02 0.01
20650 0.01 0.01
20675 0.04 0.03
20700 0.04 0.02
20725 0.01 0.01
20750 0.02 0.01
20775 0.01 0.01
20800 0.08 0.06
20825 0.01 0.01
20850 0.01 0.01
20875 0.02 0.01
20900 0.02 0.01
20925 0.01 0.01
20950 0.05 0.03
20975 0.02 0.01
21000 1.27 1.22
21025 0.01 0
21050 0.01 0.01
21075 0.03 0.01
21100 0.03 0.02
21125 0.03 0.01
21150 0.01 0.01
21175 0.02 0.01
21200 0.06 0.04
21225 0.01 0
21250 0.04 0.03
21275 0.02 0.01
21300 0.01 0.01
21325 0.01 0.01
21350 0.03 0.01
21375 0.01 0
21400 0.02 0.01
21425 0.01 0.01
21450 0.01 0.01
21475 0.02 0.01
21500 0.04 0.03
21525 0.01 0.01
21550 0.02 0.01
21575 0.01 0
21600 0.22 0.18
21625 0.01 0.01
21650 0.01 0.01
21675 0.01 0
21700 0.01 0.01
21725 0.04 0.02
21750 0.02 0.01
21775 0.01 0
21800 0.02 0.01
21825 0.02 0.01
21850 0.04 0.03
21875 0.01 0.01
21900 0.01 0.01
21925 0.01 0.01
21950 0.01 0.01
21975 0.02 0.01
22000 0.51 0.54
22025 0.01 0.01
22050 0.01 0.01
22075 0.02 0.01
22100 0.01 0.01
22125 0.01 0.01
22150 0.01 0
22175 0.01 0
22200 0.02 0.02
22225 0.01 0.01
22250 0.05 0.03
22275 0 0
22300 0.01 0.01
22325 0.01 0.01
22350 0.01 0.01
22375 0.02 0.01
22400 0.13 0.12
22425 0.02 0.01
22450 0.01 0.01
22475 0.01 0.01
22500 0.1 0.08
22525 0.01 0.01
22550 0.01 0.01
22575 0.01 0.01
22600 0.01 0.01
22625 0 0
22650 0.01 0
22675 0.02 0.01
22700 0.01 0
22725 0.01 0
22750 0.06 0.04
22775 0.01 0
22800 0.1 0.06
22825 0.01 0
22850 0.02 0.01
22875 0.03 0.02
22900 0.01 0.01
22925 0.01 0
22950 0.03 0.02
22975 0 0
23000 0.22 0.28
23025 0.01 0.01
23050 0.02 0.01
23075 0.01 0.01
23100 0.03 0.01
23125 0.01 0.01
23150 0.01 0
23175 0.01 0.01
23200 0.02 0.02
23225 0.01 0.01
23250 0.01 0.01
23275 0.01 0.01
23300 0.01 0.01
23325 0.04 0.02
23350 0.01 0.01
23375 0.01 0
23400 0.03 0.02
23425 0.01 0.01
23450 0.02 0.01
23475 0.01 0.01
23500 0.07 0.05
23525 0.01 0.01
23550 0.02 0.01
23575 0.01 0
23600 0.02 0.01
23625 0.01 0
23650 0.01 0
23675 0.03 0.02
23700 0.01 0.01
23725 0.02 0.01
23750 0.02 0.01
23775 0.01 0
23800 0.04 0.03
23825 0 0
23850 0.05 0.03
23875 0.02 0.01
23900 0.03 0.01
23925 0.03 0.01
23950 0.01 0
23975 0.03 0.01
24000 2.54 2.36
24025 0.01 0
24050 0.01 0
24075 0.01 0.01
24100 0.01 0
24125 0.03 0.01
24150 0.01 0.01
24175 0.02 0.01
24200 0.03 0.01
24225 0.01 0
24250 0.05 0.04
24275 0.01 0
24300 0.01 0.01
24325 0 0
24350 0.02 0.01
24375 0.04 0.03
24400 0.01 0.01
24425 0.01 0
24450 0.02 0.01
24475 0.01 0.01
24500 0.04 0.05
24525 0.02 0.01
24550 0.01 0.01
24575 0.03 0.02
24600 0.01 0.01
24625 0.02 0.01
24650 0.03 0.01
24675 0.01 0
24700 0.03 0.01
24725 0.01 0.01
24750 0.01 0.01
24775 0.01 0
24800 0.03 0.03
24825 0.01 0.01
24850 0.01 0.01
24875 0.01 0
24900 0.01 0.01
24925 0.04 0.03
24950 0.02 0.01
24975 0.01 0.01
25000 2.56 2.49
25025 0.01 0
25050 0.01 0.01
25075 0.02 0.01
25100 0 0
25125 0 0
25150 0.01 0.01
25175 0.01 0
25200 0.11 0.07
25225 0 0
25250 0.01 0.01
25275 0 0
25300 0.02 0.01
25325 0.01 0.01
25350 0.01 0
25375 0.01 0.01
25400 0 0
25425 0.01 0
25450 0.03 0.02
25475 0.02 0.02
25500 0.02 0.02
25525 0.01 0.01
25550 0.01 0
25575 0 0
25600 0.06 0.06
25625 0.01 0
25650 0 0
25675 0.01 0
25700 0.01 0.01
25725 0.01 0.01
25750 0.01 0.01
25775 0 0
25800 0.01 0.01
25825 0.01 0
25850 0.01 0.01
25875 0.01 0.01
25900 0.01 0.01
25925 0.01 0.01
25950 0.01 0
25975 0.03 0.02
26000 0.17 0.19
26025 0.01 0
26050 0.01 0.01
26075 0 0
26100 0.01 0
26125 0.01 0
26150 0.01 0
26175 0 0
26200 0.01 0.01
26225 0.01 0
26250 0.01 0.01
26275 0.01 0
26300 0.01 0.01
26325 0.01 0
26350 0.01 0
26375 0.05 0.03
26400 0.1 0.07
26425 0.01 0
26450 0.01 0
26475 0 0
26500 0.08 0.05
26525 0.01 0
26550 0.01 0
26575 0.01 0.01
26600 0.02 0.01
26625 0.01 0
26650 0.01 0.01
26675 0.01 0.01
26700 0.01 0
26725 0 0
26750 0.01 0.01
26775 0.01 0
26800 0.01 0.01
26825 0 0
26850 0.02 0.01
26875 0.01 0.01
26900 0 0
26925 0.01 0.01
26950 0 0
26975 0.01 0
27000 0.17 0.19
27025 0 0
27050 0.03 0.01
27075 0 0
27100 0.01 0
27125 0.01 0
27150 0.01 0.01
27175 0.01 0
27200 0.05 0.04
27225 0.01 0
27250 0 0.01
27275 0.01 0.01
27300 0.04 0.02
27325 0.01 0.01
27350 0.01 0
27375 0.01 0
27400 0.01 0
27425 0.01 0
27450 0.02 0.01
27475 0 0
27500 0.05 0.05
27525 0.01 0.01
27550 0.01 0
27575 0.04 0.03
27600 0.07 0.04
27625 0.01 0
27650 0.01 0.01
27675 0 0
27700 0.01 0
27725 0.01 0.01
27750 0.01 0
27775 0 0
27800 0.01 0
27825 0 0
27850 0.01 0
27875 0 0
27900 0.01 0
27925 0 0
27950 0 0
27975 0.01 0.01
28000 1.31 1.48
28025 0 0
28050 0.01 0
28075 0 0
28100 0.03 0.02
28125 0.01 0
28150 0.01 0
28175 0 0
28200 0.02 0.01
28225 0 0
28250 0.01 0.01
28275 0 0
28300 0 0
28325 0 0
28350 0.01 0
28375 0.01 0
28400 0 0
28425 0.01 0
28450 0 0
28475 0 0
28500 0.06 0.04
28525 0 0
28550 0.01 0.01
28575 0 0
28600 0.02 0.01
28625 0.02 0.02
28650 0.01 0
28675 0 0
28700 0.01 0
28725 0 0
28750 0.01 0
28775 0.02 0.01
28800 0.09 0.06
28825 0 0
28850 0 0
28875 0.01 0
28900 0.01 0
28925 0 0
28950 0 0
28975 0.02 0.01
29000 0.07 0.08
29025 0.01 0
29050 0.01 0
29075 0 0
29100 0.03 0.02
29125 0.01 0
29150 0 0
29175 0.03 0.02
29200 0 0
29225 0 0
29250 0.02 0.01
29275 0.01 0
29300 0 0
29325 0.02 0.01
29350 0.01 0
29375 0 0
29400 0.02 0.01
29425 0.01 0
29450 0.01 0.01
29475 0.01 0
29500 0.02 0.02
29525 0 0
29550 0 0
29575 0.01 0
29600 0.01 0.01
29625 0 0
29650 0 0
29675 0.01 0
29700 0.04 0.03
29725 0.01 0
29750 0.01 0.01
29775 0.01 0.01
29800 0.01 0
29825 0 0
29850 0.02 0.01
29875 0 0
29900 0.05 0.02
29925 0 0
29950 0.01 0
29975 0.03 0.02
30000 2.44 1.99
30025 0 0
30050 0 0
30075 0.01 0
30100 0.01 0
30125 0.01 0
30150 0.01 0
30175 0 0
30200 0 0
30225 0.03 0.02
30250 0 0
30275 0 0
30300 0.01 0
30325 0 0
30350 0.01 0
30375 0.01 0.01
30400 0.02 0.01
30425 0 0
30450 0 0
30475 0 0
30500 0.01 0.01
30525 0 0
30550 0 0
30575 0.01 0
30600 0.01 0
30625 0.01 0
30650 0 0
30675 0 0
30700 0.01 0
30725 0 0
30750 0.03 0.02
30775 0 0
30800 0.03 0.02
30825 0 0
30850 0 0
30875 0 0
30900 0 0
30925 0 0
30950 0 0
30975 0 0
31000 0.06 0.05
31025 0 0
31050 0 0
31075 0 0
31100 0 0
31125 0 0
31150 0 0
31175 0.01 0.01
31200 0.04 0.03
31225 0.01 0
31250 0 0
31275 0.01 0
31300 0.03 0.02
31325 0 0
31350 0 0
31375 0 0
31400 0 0
31425 0 0
31450 0.01 0.01
31475 0 0
31500 0.04 0.03
31525 0 0
31550 0 0
31575 0.01 0.01
31600 0 0
31625 0 0
31650 0 0
31675 0.01 0
31700 0.01 0
31725 0 0
31750 0 0
31775 0 0
31800 0 0
31825 0.02 0.01
31850 0 0
31875 0 0
31900 0.01 0
31925 0 0
31950 0 0
31975 0.01 0
32000 0.5 0.38
32025 0 0
32050 0 0
32075 0 0
32100 0.02 0.01
32125 0 0
32150 0 0
32175 0 0
32200 0.02 0.01
32225 0.01 0.01
32250 0 0
32275 0 0
32300 0 0
32325 0 0
32350 0.03 0.02
32375 0 0
32400 0.03 0.02
32425 0 0
32450 0 0
32475 0 0
32500 0.05 0.03
32525 0 0
32550 0 0
32575 0 0
32600 0 0
32625 0.01 0.01
32650 0 0
32675 0.01 0
32700 0 0
32725 0 0
32750 0.01 0.01
32775 0 0
32800 0 0
32825 0 0
32850 0 0
32875 0.01 0.01
32900 0 0
32925 0 0
32950 0.01 0.01
32975 0 0
33000 0.1 0.1
33025 0.01 0.01
33050 0 0
33075 0 0
33100 0.01 0
33125 0 0
33150 0 0
33175 0 0
33200 0 0
33225 0.01 0
33250 0 0
33275 0 0
33300 0.01 0
33325 0 0
33350 0 0
33375 0 0
33400 0 0
33425 0.02 0.02
33450 0 0
33475 0 0
33500 0.02 0.01
33525 0 0
33550 0 0
33575 0.02 0.01
33600 0.07 0.05
33625 0 0
33650 0 0
33675 0 0
33700 0.01 0
33725 0 0
33750 0.01 0
33775 0 0
33800 0 0
33825 0.01 0
33850 0 0
33875 0 0
33900 0 0
33925 0 0
33950 0.03 0.01
33975 0 0
34000 0.06 0.06
34025 0.01 0
34050 0 0
34075 0 0
34100 0.01 0
34125 0 0
34150 0 0
34175 0 0
34200 0.01 0
34225 0 0
34250 0 0
34275 0 0
34300 0.01 0
34325 0 0
34350 0.01 0
34375 0 0
34400 0 0
34425 0 0
34450 0 0
34475 0.02 0.02
34500 0.02 0.01
34525 0 0
34550 0.01 0.01
34575 0 0
34600 0 0
34625 0 0
34650 0 0
34675 0 0
34700 0 0
34725 0 0
34750 0.01 0
34775 0 0
34800 0.01 0.01
34825 0 0
34850 0 0
34875 0.01 0
34900 0 0
34925 0 0
34950 0 0
34975 0 0
35000 4.58 3.54
35025 0 0
35050 0 0
35075 0 0
35100 0 0
35125 0 0
35150 0 0
35175 0 0
35200 0 0
35225 0 0
35250 0 0
35275 0 0
35300 0 0
35325 0 0
35350 0 0
35375 0 0
35400 0 0
35425 0 0
35450 0 0
35475 0 0
35500 0 0
35525 0 0
35550 0 0
35600 0 0
35625 0 0
35650 0 0
35700 0 0
35725 0 0
35750 0 0
35775 0 0
35800 0 0
35825 0 0
35850 0 0
35875 0 0
35900 0 0
35950 0 0
35975 0 0
36000 0.08 0.08
36050 0 0
36075 0 0
36100 0 0
36125 0 0
36150 0 0
36175 0 0
36200 0 0
36225 0 0
36250 0 0
36275 0 0
36300 0 0
36325 0 0
36350 0 0
36375 0 0
36400 0 0
36425 0 0
36450 0 0
36475 0 0
36500 0 0
36525 0 0
36550 0 0
36575 0 0
36600 0 0
36625 0 0
36650 0 0
36675 0 0
36700 0 0
36725 0 0
36750 0 0
36775 0 0
36800 0 0
36825 0 0
36850 0 0
36875 0 0
36900 0 0
36950 0 0
36975 0 0
37000 0 0.01
37025 0 0
37075 0 0
37100 0 0
37125 0 0
37150 0 0
37175 0 0
37200 0 0
37225 0 0
37250 0 0
37275 0 0
37300 0 0
37325 0 0
37350 0 0
37375 0 0
37400 0 0
37450 0 0
37475 0 0
37500 0 0
37525 0 0
37550 0 0
37575 0 0
37600 0 0
37625 0 0
37675 0 0
37700 0 0
37725 0 0
37750 0 0
37775 0 0
37800 0 0
37825 0 0
37850 0 0
37875 0 0
37900 0 0
37925 0 0
37950 0 0
38000 0.01 0.01
38025 0 0
38050 0 0
38075 0 0
38100 0 0
38125 0 0
38150 0 0
38175 0 0
38200 0 0
38225 0 0
38250 0 0
38275 0 0
38300 0 0
38325 0 0
38350 0 0
38375 0 0
38400 0 0
38425 0 0
38450 0 0
38475 0 0
38500 0 0
38525 0 0
38550 0 0
38600 0 0
38625 0 0
38650 0 0
38675 0 0
38700 0 0
38725 0 0
38750 0 0
38775 0 0
38800 0 0
38825 0 0
38850 0 0
38875 0 0
38900 0 0
38925 0 0
38950 0 0
38975 0 0
39000 0 0
39075 0 0
39100 0 0
39125 0 0
39150 0 0
39175 0 0
39200 0 0
39250 0 0
39275 0 0
39325 0 0
39350 0 0
39400 0 0
39475 0 0
39500 0 0
39525 0 0
39550 0 0
39600 0 0
39625 0 0
39650 0 0
39675 0 0
39700 0 0
39750 0 0
39775 0 0
39800 0 0
39825 0 0
39850 0 0
39900 0 0
39950 0 0
39975 0 0
40000 0.42 0.4

Se observa asociaciones entre los diferentes montos del crédito, es por ello que vamos a categorizar esta variable.

In [27]:
loan['loan_amnt'].describe() #0-40k
buck = [0, 5000, 10000, 15000, 20000, 25000 , 40000]
lab = ['0-5000', '5000-10000', '10000-15000', '15000-20000', '20000-25000','25000+']
loan['loan_amnt_range'] = pd.cut(loan['loan_amnt'], buck, labels=lab)
In [28]:
purp_loan= ['loan_amnt_range', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[28]:
credit_risk Default No Default
loan_amnt_range
0-5000 10.82 14.31
5000-10000 24.12 28.92
10000-15000 22.08 20.99
15000-20000 18.03 15.36
20000-25000 11.24 9.5
25000+ 13.71 10.92
In [29]:
loan.drop(['loan_amnt'], 
          axis = 1, inplace = True)
Funded Amount & Funded Investor Amount

'Funded_amnt' es el monto total comprometido con ese préstamo en ese momento. 'Funded_amnt_inv' es la cantidad total comprometida por los inversores para ese préstamo en ese momento. Cuando no son iguales (el inversor paga menos de lo esperado), lo identificaremos como menos.

In [30]:
loan['amt_difference'] = 'Igual'
loan.loc[(loan['funded_amnt'] - loan['funded_amnt_inv']) > 0,'amt_difference'] = 'Menos'
In [31]:
loan.drop(['funded_amnt','funded_amnt_inv'],1, inplace=True)
Term

Term es el número de pagos del préstamo. Los valores están en meses y pueden ser 36 o 60. Se transforman en valores numéricos.

In [32]:
round(loan["term"].isna().sum()/len(loan)*100,2)
Out[32]:
0.0
In [33]:
loan['term'].value_counts()
Out[33]:
 36 months    976692
 60 months    306451
Name: term, dtype: int64
In [34]:
loan['term'] = loan['term'].apply(lambda s: np.int8(s.split()[0]))
plot_var('term', 'Term', continuous=False)
In [35]:
loan.groupby('term')['credit_risk'].value_counts(normalize=True).loc[:,'Default']
Out[35]:
term
36    0.160491
60    0.326189
Name: credit_risk, dtype: float64
Installment

'Installment' es pago mensual adeudado por el prestatario si se otorga el crédito.

In [36]:
plot_var('installment', 'Installment', continuous=True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [37]:
loan.groupby('credit_risk')['installment'].describe()
Out[37]:
count mean std min 25% 50% 75% max
credit_risk
Default 256711.0 461.698098 260.538134 15.91 273.92 400.24 599.47 1717.63
No Default 1026432.0 428.874358 258.758518 4.93 240.37 366.63 568.64 1719.83
Issue Date & Earliest Credit Line

'Issue Date' es el mes en que se financió el préstamo y 'Earliest Credit Line' es el mes en que se abrió la primera línea de crédito (informada del prestatario). La información que nos interesa en base a estos datos es la edad crediticia del Prestatario la cual la tenemos guardada en la variable 'mo_sin_old_il_acct' (Meses desde que se abrió la cuenta bancaria más antigua). Debido a ello, extraemos la información de éstas variables.

In [38]:
plot_var('issue_d', 'Issue Date', continuous=False)
In [39]:
from datetime import datetime
loan['issue_year'] = pd.to_datetime(loan.issue_d).dt.year
In [40]:
loan.issue_year.value_counts(normalize=True)
Out[40]:
2015    0.290703
2016    0.210265
2014    0.172598
2017    0.114449
2013    0.105049
2012    0.041591
2018    0.032195
2011    0.016928
2010    0.009771
2009    0.004116
2008    0.001865
2007    0.000470
Name: issue_year, dtype: float64
In [41]:
from datetime import datetime
loan.earliest_cr_line = pd.to_datetime(loan.earliest_cr_line)
dttoday = pd.Timestamp(datetime.now().strftime('%Y-%m-%d'))
loan['earliest_cr_line'].fillna(dttoday, inplace = True)
In [42]:
loan['Age_Borrower'] = loan.earliest_cr_line.apply(lambda x: (0 if (x==dttoday) else (np.timedelta64((x - dttoday),'D')).astype(int))/-365)
plot_var('Age_Borrower', 'Length of of the earliest Credit Line (Months to today)', continuous=True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [43]:
loan.drop(['issue_d','earliest_cr_line'],1, inplace=True)
loan.shape
Out[43]:
(1283143, 127)
Payment Plan

'Pymnt_plan' indica si se ha establecido un plan de pago para el préstamo. Como se observa en los histogramas, esta variable no tiene capacidad discriminante, es por ello que no la consideramos en el modelo.

In [44]:
plot_var('pymnt_plan', 'Payment Plan', continuous=False)
In [45]:
loan['pymnt_plan'].value_counts(dropna=False)
Out[45]:
n    1283143
Name: pymnt_plan, dtype: int64
In [46]:
loan.drop(['pymnt_plan'],1, inplace=True)
In [47]:
loan.shape
Out[47]:
(1283143, 126)
Desc

'Desc' es la descripción del préstamo proporcionada por el prestatario.

In [48]:
loan['desc'].value_counts(dropna=False)
Out[48]:
NaN                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             1157393
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    250
Debt Consolidation                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   13
  Borrower added on 03/17/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                11
  Borrower added on 02/19/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 9
  Borrower added on 03/10/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 9
Camping Membership                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    8
  Borrower added on 01/29/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 8
  Borrower added on 01/15/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 7
  Borrower added on 01/22/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 7
  Borrower added on 02/19/14 > Debt Consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 03/07/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 03/18/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 01/03/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 01/27/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 02/26/14 > Debt Consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 01/14/13 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 03/14/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 01/06/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 03/03/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 02/03/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 03/05/14 > debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 07/25/13 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 6
  Borrower added on 12/19/13 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 5
  Borrower added on 12/10/13 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 5
  Borrower added on 02/25/14 > Debt consolidation.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                5
  Borrower added on 02/06/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 5
  Borrower added on 02/05/14 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 5
  Borrower added on 01/12/13 > Debt Consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 5
  Borrower added on 09/04/13 > Debt consolidation<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 5
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ...   
  Borrower added on 02/20/14 > My loan is to pay off my credit card so I can pay it offer quicker with the lower interest rate.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   1
  Borrower added on 11/21/12 > Taking this loan to do improvements to my home including replacing the broken Central A/C unit, replacing the Kitchen appliances and remodeling the master bathroom. I am a responsible borrower &amp; would like to accomplish my home improvement project without falling in the trap of credit cards.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           1
  Borrower added on 09/12/11 > Just trying to make up the difference and acquire the rest of the loan amount i initially requested. This is for debt consolidation, so anything contributed would be greatly beneficial. Many thanks in advance!<br/>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 1
  Borrower added on 11/05/13 > payoff 3 credit cards that have a high interest rate<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               1
  Borrower added on 07/07/13 > This loan will enable us to consolidate high interest cards and proceed with the dream of establishing a dance studio in our community specializing in the art of ballet.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1
  Borrower added on 11/10/13 > I am paying off three credit cards with a very high interest rate.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 1
  Borrower added on 12/10/12 > Consolidate my credit cards.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       1
  Borrower added on 03/17/14 > I am hoping to consolidate my date and plan to use the monthly income that this will free up to step up my retirement planning.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1
I am a mother of 2 who is going to school to be a nurse.    I want to consolidate and pay educational expenses, this is a great way to do it.   My school loan and Pell grant are due, but do to a hold up at financial aid office it will come after fees are due. Part of this loan will be payed with the expected school money, but some will also be done in payments to build my credit rating.  Household gross income is $27700; I also get $158 Supplemental Security income each month for a disability.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    1
  Borrower added on 01/20/14 > My loan will be used to pay off my credit card debt. I just want to finally be debt free.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          1
  Borrower added on 11/22/13 > This loan is consolidate all my debt into a nice fixed rate which is a lower rate than what I have today.  With the money saved, I hope I can start saving for a down payment on a house.  Thank you.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1
  Borrower added on 07/18/13 > I would like to pay off some bills, my life would be a lot less stressful to only have one monthly payment .<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       1
  Borrower added on 02/05/13 > Just looking to consolidate a few credit cards and a home improvement loan, while taking advantage of a lower interest rate.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       1
  Borrower added on 08/16/13 > SOME DEBT CONSOLIDATION<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1
  Borrower added on 07/18/13 > I am tired of paying a high interest rate on all of my credit cards. I will use the loan to pay off all of my credit cards (thus increasing my credit score), combine the payments into one, and use the money I am saving in interest towards savings for the future.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             1
  Borrower added on 07/23/12 > This loan is for debt consolidation of higher interest debts (Credit Cards). I automate my payments but this will still save me money in the long run.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             1
  Borrower added on 11/04/13 > Had some financial difficulties with my aging mother who is 2500 miles away so we were using our AMEX to travel back and forth and pay for necessities. We would like to eliminate our credit card balance and have a plan to pay off the money more efficiently.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  1
  Borrower added on 08/08/12 > Tell your story. What is your loan for?<br><br> Borrower added on 08/08/12 > Time to consoldiate debt into one payment.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1
  Borrower added on 04/01/13 > i want to do only one payment a month for my credit cards  .<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       1
  Borrower added on 10/29/12 > This loan is to consolidate my credit card debt to one source.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     1
  Borrower added on 03/11/13 > Loan proceeds will be used to consolidate remaining credit card debt.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              1
  Borrower added on 04/21/12 > Much needed home improvement.  Safer living equals better life.<br><br>  Borrower added on 04/23/12 > I need to add metal roofing, as its has 40 year warranty.<br><br> Borrower added on 04/23/12 > I have excellent credit history. I will pay back 100% of loan. I have never not paid a loan off. I have 15 years of sinority, so my job is secure.<br><br> Borrower added on 04/23/12 > I will answer any questions. I have to get this loan, as banks want way to much interest, and want me to morgage my owned home for 7000.<br><br>  Borrower added on 04/24/12 > I own my home, my truck, and currently have no big payments monthly. Been working for 15 years at the same place and have sinority, so losing my job would never happen. If i am fully fundedbi can do what i need to do for my home and family.<br><br>  Borrower added on 04/27/12 > Need more investors, you will not be dissapointed in this loan. You have my word, my credit score of 775 should say it all.<br><br>  Borrower added on 04/30/12 > 5 days left come onl. I need this to put a new roof on my house, Please invest you will be 100% rewarded, because if any of you can see my credit report, i have never not paid a loan. I have paid off 3 trucks and classic car, and my home in my adult working life.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       1
  Borrower added on 12/27/13 > To consolidate credit card debt.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   1
I plan to use this money to refinance about $9000+ that I am currently paying 18.99% on and paying for my last semester of school costs (I went back to school for my BA 2-years ago and graduate next month). I have never missed or been late on a payment (the delinquency from 49-months ago was a disputed mistake) and my income is good. For clarification of my “revolving credit balance,” $95K of that is actually a second mortgage which is amortized at a fixed rate over 15 years. Another $17K is on another card, but at a much more manageable rate of 6.99%. Though my payments are manageable I could really use this loan to gain some momentum in repaying my debt quicker.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      1
  Borrower added on 10/03/13 > Loan is for home improvements including tile, carpet, flooring and several structural improvements.  Some are completed and on charge cards, some still in progress.  Loan will consolidate all expenses into one payment.  Intent is to be in this home long term.<br><br> Borrower added on 10/03/13 > Loan is to consolidate home improvement expenses into one payment.  I have always been a reliable borrower, having no late payments in over 6 years and that being only a few days due to oversight.  My employment is stable at an expanding automotive marketing firm, and pay raise expected this month.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               1
  Borrower added on 12/09/13 > we would like to purchase a honda trike<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            1
  Borrower added on 11/25/13 > Need to consolidate and eliminate old debt.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1
  Borrower added on 11/14/13 > With this loan I will be paying off the balance of my current lending club loan of 8800.00 and paying off a credit card. I have had the current loan for approx. 3 years and never late. Once completed I will have eliminated 200.00 worth of monthly payments.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   1
I am a certified independent Apple Technology Consultant who is referred by several local retail stores to companies in need of technical support (Apple employees can’t go to customer locations or troubleshoot third-party software or hardware.)  I have been in business for five years and in related fields for ten more.  My specialties include the maintenance of computer networks, internet access, and email systems; software and hardware troubleshooting; data backups; and data recovery from damaged hard drives.  I also utilize the latest technology for remote troubleshooting and can take control of client computers within seconds of a request.  I am very technically informed and receive daily several hundred confidential internal emails within the Apple Consultants Network that inform me of up-to-the-minute problems that other consultants are encountering at customer locations throughout the U.S.  I also monitor a dozen third-party technical sites covering countless issues as they occur.  For the last five years I have been going solo and have been too busy to take on new customers, but an opportunity has presented itself to take on someone with whom I’ve worked in the past who has the perfect technical expertise.  Toward this end I’ve just purchased another cargo van (that I will turn into a mobile information technology center) and I’d started to buy equipment using some special-rate credit card offers when I realized that—as silly as this may sound, as I just signed up to be a lender—I can borrow at a better rate over a longer period of time from LendingClub.com.  I still need to purchase a laptop, desktop, diagnostic software, hardware, communication equipment, storage racks for the van, switches, routers, and network cabling for inventory as well as certification classes for my new employee.  I also read many local, regional, and international newspapers daily, uncovering gems like LendingClub.com and recently noticed they have a program to trade promissory notes with FolioFN.com—another brilliant investment vehicle.  LendingClub.com is a great concept to allow the little guy (lender or borrower) to participate like the big guys.           1
  Borrower added on 11/14/13 > THIS LOAN IS TO PAY OFF CREDIT DEBT FASTER.<br>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        1
Name: desc, Length: 124204, dtype: int64
Purpose

'Purpose' es el próposito del crédito proporcionada por el prestatario para la solicitud de préstamo.

In [49]:
plot_var('purpose', 'purpose', continuous=False)
In [50]:
purp_loan= ['purpose', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[1]], loan[purp_loan[0]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[50]:
purpose car credit_card debt_consolidation educational home_improvement house major_purchase medical moving other renewable_energy small_business vacation wedding
credit_risk
Default 14.6 17.01 21.17 20.8 17.86 21.78 18.66 21.7 23.12 21.1 23.69 29.73 19.18 12.43
No Default 85.4 82.99 78.83 79.2 82.14 78.22 81.34 78.3 76.88 78.9 76.31 70.27 80.82 87.57
In [51]:
loan.loc[(loan['purpose'] == 'debt_consolidation')|(loan['purpose'] =="credit_card"), 'purpose_g'] = 'debt' 
loan.loc[(loan['purpose'] == 'home_improvement')|(loan['purpose'] =="major_purchase")|
                 (loan['purpose'] == 'car')|(loan['purpose'] =="house")|
                 (loan['purpose'] == 'vacation')|(loan['purpose'] =="renewable_energy"),
                 'purpose_g'] = 'major_purchase' 
loan.loc[(loan['purpose'] == 'small_business')|(loan['purpose'] =="medical")|
                 (loan['purpose'] == 'moving')|(loan['purpose'] =="wedding")|
                 (loan['purpose'] == 'educational'),
                 'purpose_g'] = 'life_event'
loan.loc[(loan['purpose'] == 'other'), 'purpose_g'] = 'other'
In [52]:
loan.groupby('purpose_g')['credit_risk'].value_counts(normalize=True)[:,'Default'].sort_values(ascending=False)
Out[52]:
purpose_g
life_event        0.243714
other             0.210980
debt              0.200273
major_purchase    0.180022
Name: credit_risk, dtype: float64
In [53]:
plot_var('purpose_g', 'purpose', continuous=False)
In [54]:
loan.drop('purpose', axis=1, inplace=True)
loan.select_dtypes(include=['object']).columns
Out[54]:
Index(['grade', 'sub_grade', 'emp_title', 'emp_length', 'home_ownership',
       'verification_status', 'loan_status', 'desc', 'title', 'zip_code',
       'addr_state', 'initial_list_status', 'last_pymnt_d', 'next_pymnt_d',
       'last_credit_pull_d', 'hardship_flag', 'hardship_type',
       'hardship_reason', 'hardship_status', 'hardship_start_date',
       'hardship_end_date', 'payment_plan_start_date', 'hardship_loan_status',
       'disbursement_method', 'debt_settlement_flag',
       'debt_settlement_flag_date', 'settlement_status', 'settlement_date',
       'credit_risk', 'amt_difference', 'purpose_g'],
      dtype='object')
Title

'Title' es el título del préstamo proporcionado por el prestatario.

In [55]:
loan['title'].describe()
Out[55]:
count                1268277
unique                 63148
top       Debt consolidation
freq                  624905
Name: title, dtype: object
In [56]:
loan['title'].value_counts().head(10)
Out[56]:
Debt consolidation         624905
Credit card refinancing    236816
Home improvement            70345
Other                       62604
Major purchase              22552
Debt Consolidation          15760
Medical expenses            12653
Business                    11153
Car financing               10582
Vacation                     7603
Name: title, dtype: int64
Policy Code

'Policy_code' indica que código de política se utiliza para la gestión del préstamo. Si es 1 esta disponible públicamente, en cambio 2 es cuando la información de los nuevos productos no esta disponible públicamente. Según el análisis exploratorio de esta información se tiene sólo el código 1, es asi que no la consideraremos para el modelo debido a que no tiene capacidad discriminante.

In [57]:
loan['policy_code'].value_counts()
Out[57]:
1    1283143
Name: policy_code, dtype: int64
In [58]:
plot_var('policy_code','Policy Code', continuous=False)
In [59]:
loan.drop(['policy_code'],1, inplace=True)
loan.shape
Out[59]:
(1283143, 125)
Initial List Status
In [60]:
loan['initial_list_status'].value_counts()
Out[60]:
w    732685
f    550458
Name: initial_list_status, dtype: int64
In [61]:
plot_var('initial_list_status','Initial list status', continuous=False)

Caracteristicas del Prestatario

En este apartado se agruparan las variables que hacen referencia al prestatario. Estas variables son:

  • 'Job Title': job title supplied by the Borrower when applying for the loan.
  • 'Employment Length': Employment length in years. Possible values are between 0 and 10 where 0 means less than one year and 10 means ten or more years.
  • 'Home Ownership': The home ownership status provided by the borrower during registration or obtained from the credit report. Our values are: RENT, OWN, MORTGAGE, OTHER.
  • 'Annual Income': The self-reported annual income provided by the borrower during registration.
  • 'Verification Status': Indicates if income was verified by LC, not verified, or if the income source was verified.
  • 'Zip Code': The first 3 numbers of the zip code provided by the borrower in the loan application.
  • 'Address State': The state provided by the borrower in the loan application.
Employment Length
In [62]:
loan['emp_length'].value_counts(dropna=False).sort_index()
Out[62]:
1 year        84945
10+ years    423148
2 years      116481
3 years      103042
4 years       77106
5 years       80711
6 years       60339
7 years       57610
8 years       58604
9 years       49030
< 1 year      99984
NaN           72143
Name: emp_length, dtype: int64
In [63]:
loan['emp_length'].replace('10+ years', '10 years', inplace=True)
loan['emp_length'].replace('< 1 year', '0 years', inplace=True)
loan.emp_length.map( lambda x: str(x).split()[0]).value_counts(dropna=True).sort_index()
loan['emp_length'] = loan.emp_length.map( lambda x: float(str(x).split()[0]))
plot_var('emp_length', 'Employment length', continuous=False)
In [64]:
loan.emp_length.fillna(value=0,inplace=True)
drop_list = ['emp_title','desc','title']
loan.drop(labels=drop_list, axis=1, inplace=True)
Home Ownership
In [65]:
loan['home_ownership'].value_counts()
Out[65]:
MORTGAGE    630985
RENT        513799
OWN         137859
ANY            267
OTHER          182
NONE            51
Name: home_ownership, dtype: int64
In [66]:
loan['home_ownership'].replace(['NONE','ANY'],'OTHER', inplace=True)
plot_var('home_ownership', 'Home Ownership', continuous=False)
In [67]:
purp_loan= ['home_ownership', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[67]:
credit_risk Default No Default
home_ownership
MORTGAGE 42.36 50.88
OTHER 0.04 0.04
OWN 11.07 10.66
RENT 46.54 38.42
Annual Income
In [68]:
loan['annual_inc'] = loan['annual_inc'].apply(lambda x:np.log10(x+1))
loan['annual_inc'].describe()
Out[68]:
count    1.283139e+06
mean     4.816080e+00
std      2.323322e-01
min      3.278067e+00
25%      4.662767e+00
50%      4.812920e+00
75%      4.954247e+00
max      7.041361e+00
Name: annual_inc, dtype: float64
In [69]:
loan['annual_inc'].fillna(0, inplace = True)
In [70]:
plot_var('annual_inc', 'Log10 Annual income', continuous=True);
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Verification Status
In [71]:
loan['verification_status'].value_counts()
Out[71]:
Source Verified    497395
Verified           399200
Not Verified       386548
Name: verification_status, dtype: int64
In [72]:
plot_var('verification_status', 'Verification Status', continuous=False)
In [73]:
purp_loan= ['verification_status', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[73]:
credit_risk Default No Default
verification_status
Not Verified 22.09 32.14
Source Verified 40.82 38.25
Verified 37.09 29.61
In [74]:
loan['verification_status'].replace(['Source Verified','Verified'],'Verified', inplace=True)
plot_var('verification_status', 'Estado Verificación', continuous=False)
In [75]:
di = {"Verified":1, "No Verified":0}   #converting target variable to boolean
loan = loan.replace({"verification_status": di})
Address State & Zip Code
In [76]:
loan['zip_code']=loan['zip_code'].replace(regex=['xx'], value='')
In [77]:
sns.countplot(loan['addr_state'],hue=loan['credit_risk']) 
Out[77]:
<matplotlib.axes._subplots.AxesSubplot at 0x167fef87d68>
In [78]:
# create region of residence based on state
west = ['CA', 'OR', 'UT','WA', 'CO', 'NV', 'AK', 'MT', 'HI', 'WY', 'ID']
south_west = ['AZ', 'TX', 'NM', 'OK']
south_east = ['GA', 'NC', 'VA', 'FL', 'KY', 'SC', 'LA', 'AL', 'WV', 'DC', 'AR', 'DE', 'MS', 'TN' ]
mid_west = ['IL', 'MO', 'MN', 'OH', 'WI', 'KS', 'MI', 'SD', 'IA', 'NE', 'IN', 'ND']
north_east = ['CT', 'NY', 'PA', 'NJ', 'RI','MA', 'MD', 'VT', 'NH', 'ME']

def finding_regions(state):
    if state in west:
        return 'West'
    elif state in south_west:
        return 'SouthWest'
    elif state in south_east:
        return 'SouthEast'
    elif state in mid_west:
        return 'MidWest'
    elif state in north_east:
        return 'NorthEast'
In [79]:
loan['region'] = loan['addr_state'].apply(finding_regions)
loan['region'].isnull().sum()
Out[79]:
0
In [80]:
plot_var('region', 'US Region', continuous=False)
In [81]:
loan.drop(['addr_state','zip_code'], 
          axis = 1, inplace = True)

Evaluación del Prestatario

En este apartado se agruparan las variables que hacen referencia a información resultante de la evaluación del prestatario. Estas variables son:

  • 'Interest Rate': Interest Rate on the loan.
  • 'Grade': LC assigned loan grade.
  • 'Sub Grade': LC assigned loan subgrade.
Interest Rate
In [82]:
plot_var('int_rate', 'Interest Rate', continuous=True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [83]:
order_sub = loan.groupby("grade")['int_rate'].count().index
g2 = sns.boxenplot(x="grade", y="int_rate", data=loan, 
                   palette="hls", order=order_sub)
g2.set_xlabel("Grade Values", fontsize=15)
g2.set_ylabel("Interest Rate", fontsize=15)
g2.set_title("Lending Club Loan - Interest Rate Distribution by Sub-Grade", fontsize=20)

plt.subplots_adjust(hspace = 0.4,top = 0.9)

plt.show()
Grade y Sub Grade

Convertimos esta variable en valores numéricos, según el grado de riesgo del préstamo, a fin de reducir la complejidad del modelo. Prescindiremos de la variable 'subgrade' por considerar que contiene información reiterativa.

In [84]:
grade_mapping={'A':7,'B':6,'C':5,'D':4,'E':3,'F':2,'G':1}
loan["grade"] = loan["grade"].replace(grade_mapping)
In [85]:
loan.drop(['sub_grade'],axis = 1, inplace = True)
In [86]:
plot_var('grade','Grade',continuous=False)
In [87]:
purp_loan= ['credit_risk','grade']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[87]:
grade 1 2 3 4 5 6 7
credit_risk
Default 49.64 45.21 38.53 30.38 22.44 13.41 6.04
No Default 50.36 54.79 61.47 69.62 77.56 86.59 93.96

Historial Crediticio del Prestatario

Bajo este epígrafe agruparemos todas las variables que describen el historial crediticio del usuario.

  • 'delinq_2yrs' : The number of 30+ days past-due incidences of delinquency in the borrower's credit file for the past 2 years.
  • 'inq_last_6mths' : The number of inquiries in past 6 months (excluding auto and mortgage inquiries).
  • 'mths_since_last_delinq' : The number of months since the borrower's last delinquency.
  • 'mths_since_last_record' : The number of months since the last public record.
  • 'pub_rec' : Number of derogatory public records.
  • 'collections_12_mths_ex_med' : Number of collections in 12 months excluding medical collections.
  • 'mths_since_last_major_derog' : Months since most recent 90-day or worse rating.
  • 'tot_coll_amt' : Total collection amounts ever owed.
  • 'open_acc_6m' : Number of open trades in last 6 months.
  • 'open_act_il' : Number of currently active installment trades.
  • 'open_il_12m' : Number of installment accounts opened in past 12 months.
  • 'open_il_24m' : Number of installment accounts opened in past 24 months.
  • 'mths_since_rcnt_il' : Months since most recent installment accounts opened.
  • 'open_rv_12m' : Number of revolving trades opened in past 12 months.
  • 'open_rv_24m' : Number of revolving trades opened in past 24 months.
  • 'inq_fi' : Number of personal finance inquiries.
  • 'inq_last_12m' : Number of credit inquiries in past 12 months.
  • 'acc_open_past_24mths' : Number of trades opened in past 24 months.
  • 'chargeoff_within_12_mths' : Number of charge-offs within 12 months.
  • 'mo_sin_old_il_acct' : Months since oldest bank installment account opened.
  • 'mo_sin_old_rev_tl_op' : Months since oldest revolving account opened.
  • 'mo_sin_rcnt_rev_tl_op' : Months since most recent revolving account opened.
  • 'mo_sin_rcnt_tl' : Months since most recent account opened.
  • 'num_accts_ever_120_pd' : Number of accounts ever 120 or more days past due.
  • 'num_actv_bc_tl' : Number of currently active bankcard accounts.
  • 'num_actv_rev_tl' : Number of currently active revolving trades.
  • 'num_bc_sats' : Number of satisfactory bankcard accounts.
  • 'num_bc_tl' : Number of bankcard accounts.
  • 'num_il_tl' : Number of installment accounts.
  • 'num_op_rev_tl' : Number of open revolving accounts.
  • 'num_rev_accts' : Number of revolving accounts.
  • 'num_rev_tl_bal_gt_0' : Number of revolving trades with balance >0.
  • 'num_sats' : Number of satisfactory accounts.
  • 'num_tl_120dpd_2m' : Number of accounts currently 120 days past due (updated in past 2 months).
  • 'num_tl_30dpd' : Number of accounts currently 30 days past due (updated in past 2 months).
  • 'num_tl_90g_dpd_24m' : Number of accounts 90 or more days past due in last 24 months.
  • 'num_tl_op_past_12m' : Number of accounts opened in past 12 months.
  • 'pct_tl_nvr_dlq' : Percent of trades never delinquent.
  • 'percent_bc_gt_75' : Percentage of all bankcard accounts > 75% of limit.
  • 'pub_rec_bankruptcies' : Number of public record bankruptcies.
  • 'tax_liens' : Number of tax liens.
  • 'tot_hi_cred_lim' : Total high credit/credit limit.
  • 'total_bal_ex_mort' : Total credit balance excluding mortgage.
  • 'total_bc_limit' : Total bankcard high credit/credit limit.
  • 'total_il_high_credit_limit' : Total installment high credit/credit limit.

En primer lugar, calculamos correlaciones entre las variables. Como se puede observar, existe una gran correlación entre variables, porque recoger información parecida. En este sentido, se decide conservar una variable representativa de la información, y prescindir del resto.

In [88]:
matrix_corr(loan[['delinq_2yrs', 'inq_last_6mths', 'mths_since_last_delinq',
                  'mths_since_last_record', 'pub_rec', 'collections_12_mths_ex_med',
                  'mths_since_last_major_derog','tot_coll_amt',
                  'open_acc_6m','open_act_il','open_il_12m','open_il_24m',
                  'mths_since_rcnt_il','open_rv_12m','open_rv_24m',
                  'inq_fi','inq_last_12m','acc_open_past_24mths',
                  'chargeoff_within_12_mths','mo_sin_old_il_acct',
                  'mo_sin_old_rev_tl_op','mo_sin_rcnt_rev_tl_op',
                  'mo_sin_rcnt_tl']], mirror=False)
In [89]:
matrix_corr(loan[['num_accts_ever_120_pd', 'num_actv_bc_tl', 'num_actv_rev_tl',
       'num_bc_sats', 'num_bc_tl', 'num_il_tl', 'num_op_rev_tl',
       'num_rev_accts', 'num_rev_tl_bal_gt_0', 'num_sats', 'num_tl_120dpd_2m',
       'num_tl_30dpd', 'num_tl_90g_dpd_24m', 'num_tl_op_past_12m',
       'pct_tl_nvr_dlq', 'percent_bc_gt_75', 'pub_rec_bankruptcies',
       'tax_liens', 'tot_hi_cred_lim', 'total_bal_ex_mort', 'total_bc_limit',
       'total_il_high_credit_limit']], mirror=False)

Para eliminar redundancias en cuanto a número de cuentas, seleccionamos la variable 'Number of satisfactory accounts' (num_sats) y eliminamos las variables que contienen información similar:

In [90]:
loan.drop(['num_actv_rev_tl','num_actv_bc_tl','num_bc_sats','num_bc_tl','num_op_rev_tl','num_rev_accts','num_rev_tl_bal_gt_0'], 
          axis = 1, inplace = True)
In [91]:
loan.shape
Out[91]:
(1283143, 113)
Deliquency in last 2 years

El número de más de 30 días de incidencias vencidas de morosidad en el archivo de crédito del prestatario durante los últimos 2 años.

In [92]:
loan['delinq_2yrs'].isnull().sum()
Out[92]:
29

Las observaciones ausentes significan que no los individuos no han tenido episodios de morosidad durante los últimos 2 años, es así que los replazamos por valor 0.

In [93]:
loan['delinq_2yrs'].fillna(0, inplace = True) 
In [94]:
plot_var('delinq_2yrs', 'Delinquency in last 2 years',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Para facilitar el análisis del modelo, por que el 80% de casos (Default y No Default) es valor 0 (Por tener mucho bias el grafico de boxplot lo identifica como outliers), se convertirá esta variable como un indicador si el prestatario tuvo un episodio de morosidad durante los últimos 2 años. (0 que no tiene, y 1 que si tuvo por lo menos un episodio)

In [95]:
purp_loan= ['delinq_2yrs', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[95]:
credit_risk Default No Default
delinq_2yrs
0.0 79.26 81.1
1.0 13.38 12.66
2.0 4.19 3.64
3.0 1.58 1.31
4.0 0.71 0.58
5.0 0.37 0.3
6.0 0.2 0.16
7.0 0.12 0.09
8.0 0.06 0.05
9.0 0.04 0.03
10.0 0.03 0.02
11.0 0.02 0.01
12.0 0.02 0.01
13.0 0.01 0.01
14.0 0.01 0.01
15.0 0 0
16.0 0 0
17.0 0 0
18.0 0 0
19.0 0 0
20.0 0 0
21.0 0 0
22.0 0 0
24.0 0 0
25.0 0 0
26.0 0 0
27.0 0 0
29.0 0 0
30.0 0 0
39.0 0 0
In [96]:
loan["delinq_2yrs_cat"] = 0
loan.loc[loan["delinq_2yrs"] > 0, "delinq_2yrs_cat"] = 1
In [97]:
purp_loan= ['delinq_2yrs_cat', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[97]:
credit_risk Default No Default
delinq_2yrs_cat
0 79.26 81.1
1 20.74 18.9
In [98]:
loan.drop(['delinq_2yrs'], 
          axis = 1, inplace = True)
Inquires Last 6 Months

Una 'inquiry' es una comprobación que realiza Lending Club sobre las operaciones realizadas por el prestatario. Estas pueden ser 'soft' (en operaciones menores, que no afectan al credit score) o 'hard' (en operaciones de mayor riesgo, como hipotecas o líneas de crédito extra). Las soft inquiries no afectan al credit score. Por el contrario, una hard inquiry puede tener un mínimo impacto sobre el credit score del prestamista (1 a 5 puntos). Sólo la acumulación de hard inquiries tienen un impacto real.

https://help.lendingclub.com/hc/en-us/articles/213803238-Understanding-your-credit-score

Dado que esta variable no distingue entre soft y hard inquiries, consideramos que la inclusión de esta variable podría distorsionar el resultado, por lo que se decide prescindir de ella.

In [99]:
loan.drop(['inq_last_6mths'], 
          axis = 1, inplace = True)
Number of derogatory public records

'pub rec' guarda el número de registros públicos despectivos. Los casos con valores NaN significa que el prestatario no tiene registros públicos y se imputarán a 0.

In [100]:
loan['pub_rec'].isnull().sum()
Out[100]:
29
In [101]:
loan['pub_rec'].fillna(0, inplace = True) 
In [102]:
plot_var('pub_rec', 'Derogatory public records',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [103]:
purp_loan= ['pub_rec', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[103]:
credit_risk Default No Default
pub_rec
0.0 80.7 83.68
1.0 16.03 13.68
2.0 2.17 1.74
3.0 0.63 0.53
4.0 0.24 0.18
5.0 0.11 0.09
6.0 0.06 0.05
7.0 0.02 0.02
8.0 0.01 0.01
9.0 0.01 0.01
10.0 0 0
11.0 0 0
12.0 0 0
13.0 0 0
14.0 0 0
15.0 0 0
16.0 0 0
17.0 0 0
18.0 0 0
19.0 0 0
20.0 0 0
21.0 0 0
22.0 0 0
23.0 0 0
24.0 0 0
25.0 0 0
28.0 0 0
34.0 0 0
37.0 0 0
40.0 0 0
46.0 0 0
47.0 0 0
49.0 0 0
54.0 0 0
61.0 0 0
63.0 0 0
86.0 0 0

Se observa que alrededor del 80% de casos (Default y No Default) tiene valor 0 (Por tener mucho bias el grafico de boxplot lo identifica como outliers). De forma similar a la variable Delinq 2 yrs, se convertirá esta variable como un indicador si el prestatario tiene al menos un registro público.

In [104]:
loan["pub_rec_cat"] = 0
loan.loc[loan["pub_rec"]>0,"pub_rec_cat"] = 1
In [105]:
purp_loan= ['pub_rec_cat', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[105]:
credit_risk Default No Default
pub_rec_cat
0 80.7 83.68
1 19.3 16.32
In [106]:
loan.drop(['pub_rec'], 
          axis = 1, inplace = True)
Months since last deliquency

El número de meses desde la última morosidad del prestatario. Las observaciones ausentes significan que los individuos no han tenido episodios de morosidad, es así que los replazamos por valor 0.

In [107]:
loan['mths_since_last_delinq'].isnull().sum()
Out[107]:
647006
In [108]:
loan['mths_since_last_delinq'].fillna(0, inplace = True) 
In [109]:
plot_var('mths_since_last_delinq', 'Months since last deliquency',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [110]:
purp_loan= ['mths_since_last_delinq', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[110]:
credit_risk Default No Default
mths_since_last_delinq
0.0 48.81 51.03
1.0 0.4 0.36
2.0 0.54 0.46
3.0 0.64 0.57
4.0 0.77 0.67
5.0 0.88 0.78
6.0 1.07 0.91
7.0 1.01 0.9
8.0 0.98 0.9
9.0 1.02 0.92
10.0 0.95 0.88
11.0 0.92 0.86
12.0 1.02 0.93
13.0 1.03 0.92
14.0 0.97 0.9
15.0 0.99 0.88
16.0 0.89 0.84
17.0 0.9 0.83
18.0 0.89 0.84
19.0 0.86 0.84
20.0 0.82 0.81
21.0 0.85 0.82
22.0 0.85 0.8
23.0 0.8 0.79
24.0 0.81 0.79
25.0 0.83 0.8
26.0 0.86 0.8
27.0 0.81 0.76
28.0 0.8 0.78
29.0 0.8 0.75
30.0 0.78 0.74
31.0 0.76 0.74
32.0 0.73 0.71
33.0 0.73 0.71
34.0 0.72 0.71
35.0 0.68 0.71
36.0 0.7 0.7
37.0 0.7 0.69
38.0 0.7 0.68
39.0 0.67 0.67
40.0 0.66 0.67
41.0 0.65 0.65
42.0 0.65 0.65
43.0 0.64 0.64
44.0 0.63 0.64
45.0 0.63 0.63
46.0 0.61 0.61
47.0 0.6 0.6
48.0 0.58 0.6
49.0 0.53 0.53
50.0 0.43 0.44
51.0 0.46 0.42
52.0 0.43 0.42
53.0 0.43 0.43
54.0 0.46 0.43
55.0 0.43 0.42
56.0 0.43 0.43
57.0 0.43 0.43
58.0 0.43 0.42
59.0 0.43 0.41
60.0 0.42 0.42
61.0 0.44 0.42
62.0 0.43 0.41
63.0 0.43 0.4
64.0 0.4 0.41
65.0 0.42 0.4
66.0 0.42 0.4
67.0 0.4 0.41
68.0 0.42 0.4
69.0 0.41 0.38
70.0 0.42 0.39
71.0 0.38 0.37
72.0 0.37 0.37
73.0 0.37 0.38
74.0 0.37 0.36
75.0 0.35 0.36
76.0 0.34 0.34
77.0 0.31 0.32
78.0 0.3 0.31
79.0 0.3 0.3
80.0 0.28 0.29
81.0 0.27 0.26
82.0 0.11 0.11
83.0 0.02 0.02
84.0 0.01 0.01
85.0 0.01 0.01
86.0 0.01 0.01
87.0 0.01 0.01
88.0 0.01 0.01
89.0 0.01 0
90.0 0 0
91.0 0 0
92.0 0.01 0
93.0 0 0
94.0 0 0
95.0 0 0
96.0 0 0
97.0 0 0
98.0 0 0
99.0 0 0
100.0 0 0
101.0 0 0
102.0 0 0
103.0 0 0
104.0 0 0
105.0 0 0
106.0 0 0
107.0 0 0
108.0 0 0
109.0 0 0
110.0 0 0
111.0 0 0
112.0 0 0
113.0 0 0
114.0 0 0
115.0 0 0
116.0 0 0
117.0 0 0
118.0 0 0
119.0 0 0
120.0 0 0
121.0 0 0
122.0 0 0
123.0 0 0
124.0 0 0
125.0 0 0
126.0 0 0
127.0 0 0
129.0 0 0
130.0 0 0
131.0 0 0
132.0 0 0
133.0 0 0
134.0 0 0
135.0 0 0
136.0 0 0
137.0 0 0
139.0 0 0
140.0 0 0
141.0 0 0
142.0 0 0
143.0 0 0
146.0 0 0
148.0 0 0
149.0 0 0
151.0 0 0
152.0 0 0
154.0 0 0
156.0 0 0
157.0 0 0
158.0 0 0
159.0 0 0
160.0 0 0
161.0 0 0
170.0 0 0
171.0 0 0
176.0 0 0
178.0 0 0
180.0 0 0
188.0 0 0
192.0 0 0
202.0 0 0
226.0 0 0
Months since last record

El número de meses desde el último registro público. Las observaciones ausentes significan que los individuos no han tenido episodios de morosidad, es así que los replazamos por valor 0.

In [111]:
loan['mths_since_last_record'].isnull().sum()
Out[111]:
1064777
In [112]:
loan['mths_since_last_record'].fillna(0, inplace = True) 
In [113]:
plot_var('mths_since_last_record', 'Months since last record',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [114]:
purp_loan= ['mths_since_last_record', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[114]:
credit_risk Default No Default
mths_since_last_record
0.0 80.71 83.68
1.0 0.01 0.01
2.0 0.01 0.01
3.0 0.02 0.01
4.0 0.02 0.02
5.0 0.03 0.02
6.0 0.03 0.02
7.0 0.03 0.03
8.0 0.03 0.03
9.0 0.04 0.03
10.0 0.05 0.03
11.0 0.05 0.03
12.0 0.05 0.04
13.0 0.04 0.03
14.0 0.05 0.04
15.0 0.04 0.04
16.0 0.05 0.04
17.0 0.04 0.04
18.0 0.06 0.05
19.0 0.05 0.05
20.0 0.05 0.05
21.0 0.05 0.05
22.0 0.06 0.05
23.0 0.06 0.06
24.0 0.07 0.06
25.0 0.08 0.06
26.0 0.08 0.06
27.0 0.08 0.07
28.0 0.08 0.07
29.0 0.09 0.07
30.0 0.08 0.08
31.0 0.09 0.08
32.0 0.1 0.08
33.0 0.11 0.09
34.0 0.1 0.1
35.0 0.1 0.09
36.0 0.11 0.1
37.0 0.13 0.11
38.0 0.12 0.12
39.0 0.14 0.11
40.0 0.13 0.12
41.0 0.14 0.12
42.0 0.15 0.13
43.0 0.15 0.13
44.0 0.14 0.14
45.0 0.16 0.14
46.0 0.17 0.15
47.0 0.16 0.16
48.0 0.17 0.16
49.0 0.17 0.16
50.0 0.17 0.16
51.0 0.18 0.17
52.0 0.2 0.18
53.0 0.2 0.19
54.0 0.22 0.2
55.0 0.23 0.2
56.0 0.23 0.2
57.0 0.23 0.21
58.0 0.25 0.21
59.0 0.24 0.2
60.0 0.25 0.21
61.0 0.25 0.22
62.0 0.25 0.23
63.0 0.27 0.23
64.0 0.26 0.23
65.0 0.25 0.22
66.0 0.27 0.23
67.0 0.27 0.24
68.0 0.27 0.23
69.0 0.29 0.24
70.0 0.29 0.24
71.0 0.31 0.24
72.0 0.28 0.24
73.0 0.27 0.24
74.0 0.3 0.23
75.0 0.29 0.24
76.0 0.29 0.24
77.0 0.28 0.24
78.0 0.3 0.23
79.0 0.29 0.24
80.0 0.29 0.24
81.0 0.3 0.23
82.0 0.31 0.22
83.0 0.27 0.21
84.0 0.23 0.18
85.0 0.24 0.19
86.0 0.26 0.19
87.0 0.26 0.18
88.0 0.21 0.18
89.0 0.22 0.16
90.0 0.21 0.16
91.0 0.22 0.15
92.0 0.21 0.16
93.0 0.18 0.16
94.0 0.19 0.15
95.0 0.19 0.15
96.0 0.2 0.14
97.0 0.18 0.15
98.0 0.17 0.15
99.0 0.16 0.14
100.0 0.19 0.14
101.0 0.17 0.14
102.0 0.18 0.14
103.0 0.18 0.14
104.0 0.16 0.14
105.0 0.17 0.14
106.0 0.15 0.13
107.0 0.16 0.13
108.0 0.16 0.14
109.0 0.15 0.14
110.0 0.13 0.13
111.0 0.15 0.13
112.0 0.15 0.14
113.0 0.15 0.14
114.0 0.16 0.14
115.0 0.15 0.14
116.0 0.15 0.14
117.0 0.14 0.14
118.0 0.14 0.14
119.0 0.08 0.07
120.0 0 0
121.0 0 0
123.0 0 0
129.0 0 0
Months since last major derogative

Meses desde la calificación más reciente de 90 días o peor. Las observaciones ausentes significan que los individuos no han tenido episodios de morosidad, es así que los replazamos por valor 0.

In [115]:
loan['mths_since_last_major_derog'].isnull().sum()
Out[115]:
946333
In [116]:
loan['mths_since_last_major_derog'].fillna(0, inplace = True) 
In [117]:
plot_var('mths_since_last_major_derog', 'Months since last major derogative',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [118]:
purp_loan= ['mths_since_last_major_derog', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[118]:
credit_risk Default No Default
mths_since_last_major_derog
0.0 71.18 74.42
1.0 0.09 0.07
2.0 0.1 0.08
3.0 0.1 0.09
4.0 0.15 0.11
5.0 0.17 0.15
6.0 0.22 0.18
7.0 0.24 0.19
8.0 0.25 0.2
9.0 0.27 0.21
10.0 0.26 0.22
11.0 0.26 0.21
12.0 0.32 0.25
13.0 0.31 0.28
14.0 0.33 0.27
15.0 0.32 0.28
16.0 0.31 0.29
17.0 0.33 0.29
18.0 0.35 0.3
19.0 0.32 0.29
20.0 0.34 0.31
21.0 0.36 0.32
22.0 0.38 0.32
23.0 0.37 0.32
24.0 0.38 0.35
25.0 0.4 0.36
26.0 0.42 0.37
27.0 0.39 0.36
28.0 0.42 0.37
29.0 0.4 0.37
30.0 0.41 0.36
31.0 0.42 0.37
32.0 0.41 0.37
33.0 0.4 0.37
34.0 0.41 0.37
35.0 0.42 0.37
36.0 0.45 0.37
37.0 0.45 0.39
38.0 0.42 0.4
39.0 0.43 0.38
40.0 0.44 0.4
41.0 0.42 0.4
42.0 0.45 0.4
43.0 0.44 0.4
44.0 0.42 0.4
45.0 0.44 0.41
46.0 0.43 0.4
47.0 0.42 0.39
48.0 0.44 0.39
49.0 0.43 0.37
50.0 0.37 0.35
51.0 0.4 0.35
52.0 0.38 0.36
53.0 0.38 0.36
54.0 0.41 0.35
55.0 0.38 0.35
56.0 0.39 0.36
57.0 0.38 0.35
58.0 0.38 0.35
59.0 0.39 0.35
60.0 0.38 0.35
61.0 0.39 0.35
62.0 0.4 0.35
63.0 0.4 0.34
64.0 0.39 0.35
65.0 0.38 0.35
66.0 0.38 0.35
67.0 0.38 0.35
68.0 0.36 0.35
69.0 0.39 0.34
70.0 0.39 0.34
71.0 0.37 0.32
72.0 0.35 0.32
73.0 0.34 0.32
74.0 0.36 0.3
75.0 0.33 0.29
76.0 0.32 0.28
77.0 0.26 0.24
78.0 0.24 0.22
79.0 0.25 0.2
80.0 0.21 0.18
81.0 0.19 0.16
82.0 0.1 0.08
83.0 0.03 0.03
84.0 0.02 0.02
85.0 0.02 0.02
86.0 0.02 0.01
87.0 0.01 0.01
88.0 0.01 0.01
89.0 0.01 0.01
90.0 0.01 0.01
91.0 0.01 0.01
92.0 0.01 0.01
93.0 0.01 0.01
94.0 0.01 0.01
95.0 0.01 0.01
96.0 0.01 0
97.0 0.01 0
98.0 0.01 0.01
99.0 0 0
100.0 0 0
101.0 0 0
102.0 0 0
103.0 0 0
104.0 0 0
105.0 0 0
106.0 0 0
107.0 0 0
108.0 0 0
109.0 0 0
110.0 0 0
111.0 0 0
112.0 0 0
113.0 0 0
114.0 0 0
115.0 0 0
116.0 0 0
117.0 0 0
118.0 0 0
119.0 0 0
120.0 0 0
121.0 0 0
122.0 0 0
123.0 0 0
124.0 0 0
125.0 0 0
126.0 0 0
127.0 0 0
129.0 0 0
130.0 0 0
131.0 0 0
132.0 0 0
133.0 0 0
134.0 0 0
135.0 0 0
136.0 0 0
137.0 0 0
138.0 0 0
139.0 0 0
140.0 0 0
141.0 0 0
142.0 0 0
143.0 0 0
144.0 0 0
145.0 0 0
146.0 0 0
147.0 0 0
148.0 0 0
149.0 0 0
150.0 0 0
151.0 0 0
152.0 0 0
153.0 0 0
154.0 0 0
156.0 0 0
157.0 0 0
158.0 0 0
159.0 0 0
160.0 0 0
161.0 0 0
162.0 0 0
165.0 0 0
170.0 0 0
171.0 0 0
175.0 0 0
176.0 0 0
178.0 0 0
180.0 0 0
188.0 0 0
192.0 0 0
197.0 0 0
202.0 0 0
226.0 0 0
Collections 12 Months (Exclude Medical Credits)

Número de cobros en 12 meses excluyendo cobros médicos.Las Observaciones ausentes se van a imputar a 0, dado que representan los que no han tenido cobros en el último año.

In [119]:
loan['collections_12_mths_ex_med'].isnull().sum()
Out[119]:
145
In [120]:
loan['collections_12_mths_ex_med'].fillna(0, inplace = True) 
In [121]:
plot_var('collections_12_mths_ex_med', 'Collections 12 Months',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Total collection amount

Montos totales de cobro adeudados. Las observaciones ausentes se imputaran a 0 dado que representan los casos que no tienen registros de cobros.

In [122]:
loan['tot_coll_amt'].isnull().sum()
Out[122]:
70276
In [123]:
loan['tot_coll_amt'].fillna(0, inplace = True) 
In [124]:
plot_var('tot_coll_amt', 'Total collection amounts ever owed',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Accounts open past 24 months

Número de operaciones abiertas en los últimos 24 meses. Las observaciones ausentes representan los solicitantes que no han abierto cuentas durante los últimos 24 meses.

In [125]:
loan['acc_open_past_24mths'].isnull().sum()
Out[125]:
50030
In [126]:
loan['acc_open_past_24mths'].fillna(0, inplace = True) 
In [127]:
plot_var('acc_open_past_24mths', 'Number of trades opened in past 24 months',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Chargeoff within 12 months

Número de eventos impagos dentro de los 12 meses. Las observaciones ausentes se imputaran a 0 dado que no han reportado eventos de cuentas impagables.

In [128]:
loan['chargeoff_within_12_mths'].isnull().sum()
Out[128]:
145
In [129]:
loan['chargeoff_within_12_mths'].fillna(0, inplace = True) 
In [130]:
plot_var('chargeoff_within_12_mths', 'Number of charge-offs within 12 months',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Months since old Credit Account

Meses desde que se abrió la cuenta bancaria más antigua.

In [131]:
loan['mo_sin_old_il_acct'].isnull().sum()
Out[131]:
106370
In [132]:
loan['mo_sin_old_il_acct'].fillna(0, inplace = True) 
In [133]:
plot_var('mo_sin_old_il_acct', 'Months since oldest bank installment account opened',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Months since old opened revolvent account

Meses desde que se abrió la cuenta rotativa más antigua.

In [134]:
loan['mo_sin_old_rev_tl_op'].isnull().sum()
Out[134]:
70277
In [135]:
loan['mo_sin_old_rev_tl_op'].fillna(0, inplace = True) 
In [136]:
plot_var('mo_sin_old_rev_tl_op', 'Months since oldest revolving account opened',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Months since recent opened account

Meses desde que se abrió la cuenta más reciente. Se imputaran las observaciones ausentes.

In [137]:
loan['mo_sin_rcnt_tl'].isnull().sum()
Out[137]:
70276
In [138]:
loan['mo_sin_rcnt_tl'].fillna(0, inplace = True) 
In [139]:
plot_var('mo_sin_rcnt_tl', 'Months since most recent account opened',
         continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Number of accounts ever 120 or more days past due
In [140]:
loan['num_accts_ever_120_pd'].isnull().sum()
Out[140]:
70276
In [141]:
loan['num_accts_ever_120_pd'].fillna(0, inplace = True) 
In [142]:
plot_var('num_accts_ever_120_pd', 'Number of accounts ever 120 or more days past due', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Mantenemos la variable por considerar que tiene valor discriminante.

Number of installment accounts
In [143]:
loan['num_il_tl'].isnull().sum()
Out[143]:
70276
In [144]:
loan['num_il_tl'].fillna(0, inplace = True) 
In [145]:
plot_var('num_il_tl', 'Number of installment accounts', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Eliminamos la variable por considerar que no posee poder discriminante.

In [146]:
loan.drop(['num_il_tl'], axis = 1, inplace = True)
Number of accounts currently 120 days past due (updated in past 2 months)
In [147]:
loan['num_tl_120dpd_2m'].isnull().sum()
Out[147]:
118319
In [148]:
loan['num_tl_120dpd_2m'].fillna(0, inplace = True) 
In [149]:
plot_var('num_tl_120dpd_2m', 'Number of accounts currently 120 days past due', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Prescindimos de la variable por no tener poder predictivo.

In [150]:
loan.drop(['num_tl_120dpd_2m'], axis = 1, inplace = True)
Number of accounts currently 30 days past due (updated in past 2 months)
In [151]:
loan['num_tl_30dpd'].isnull().sum()
Out[151]:
70276
In [152]:
loan['num_tl_30dpd'].fillna(0, inplace = True) 
In [153]:
plot_var('num_tl_30dpd', 'Number of accounts currently 30 days past due', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Eliminamos la variable.

In [154]:
loan.drop(['num_tl_30dpd'], axis = 1, inplace = True)
Number of accounts 90 or more days past due in last 24 months
In [155]:
loan['num_tl_90g_dpd_24m'].isnull().sum()
Out[155]:
70276
In [156]:
loan['num_tl_90g_dpd_24m'].fillna(0, inplace = True) 
In [157]:
plot_var('num_tl_90g_dpd_24m', 'Number of accounts 90 or more days past due in last 24 months', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Number of accounts opened in past 12 months
In [158]:
loan['num_tl_op_past_12m'].isnull().sum()
Out[158]:
70276
In [159]:
loan['num_tl_op_past_12m'].fillna(0, inplace = True)
In [160]:
plot_var('num_tl_op_past_12m', 'Number of accounts opened in past 12 months', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Eliminamos la variable, ya que los préstamos default y no default presentan comportamientos similares en esta variable y no permite predecir.

In [161]:
loan.drop(['num_tl_op_past_12m'], axis = 1, inplace = True)
Percent of trades never delinquent
In [162]:
loan['pct_tl_nvr_dlq'].isna().sum()
Out[162]:
70430
In [163]:
loan['pct_tl_nvr_dlq'].fillna(0, inplace = True)
In [164]:
plot_var('pct_tl_nvr_dlq', 'Percent of trades never delinquent', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Prescindimos de esta variable.

In [165]:
loan.drop(['pct_tl_nvr_dlq'], axis = 1, inplace = True)
Percentage of all bankcard accounts > 75% of limit.
In [166]:
loan['percent_bc_gt_75'].isna().sum()
Out[166]:
63264
In [167]:
loan['percent_bc_gt_75'].fillna(0, inplace = True)
In [168]:
plot_var('percent_bc_gt_75', 'Percentage of all bankcard accounts > 75% of limit', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Number of public record bankruptcies
In [169]:
loan['pub_rec_bankruptcies'].isna().sum()
Out[169]:
1365
In [170]:
loan['pub_rec_bankruptcies'].fillna(0, inplace = True)
In [171]:
plot_var('pub_rec_bankruptcies', 'Number of public record bankruptcies', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Esta variable no posee poder discriminante, por lo que la eliminamos del estudio.

In [172]:
loan.drop(['pub_rec_bankruptcies'], axis = 1, inplace = True)
In [173]:
loan.drop(['open_acc_6m','open_act_il','open_il_12m',
           'open_il_24m','mths_since_rcnt_il','open_rv_12m',
           'open_rv_24m','inq_fi','inq_last_12m','mo_sin_rcnt_rev_tl_op'
          ], axis = 1, inplace = True)
loan.shape
Out[173]:
(1283143, 96)

Endeudamiento del Prestatario

Esta sección esta representada por el Ratio DTI.

Total monthly debt payments on the total debt obligations (DTI)
In [174]:
loan['dti'].describe()
Out[174]:
count    1.283143e+06
mean     1.800362e+01
std      8.359684e+00
min     -1.000000e+00
25%      1.174000e+01
50%      1.752000e+01
75%      2.388000e+01
max      4.996000e+01
Name: dti, dtype: float64
In [175]:
f, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(12,3), dpi=90)
sns.distplot(loan.loc[loan['dti'].notnull() & (loan['dti'] < 60), 'dti'], kde=False, ax=ax1)
ax1.set_xlabel('dti')
ax1.set_ylabel('Count')
ax1.set_title('Deuda a Ingresos')
sns.boxplot(x=loan.loc[loan['dti'].notnull() & (loan['dti'] < 60), 'dti'], y='credit_risk', data=loan, ax=ax2)
ax2.set_xlabel('DTI')
ax2.set_ylabel('Proporcion de préstamos pagados')
ax2.set_title('Tasa totalmente pagada a ingresos')
ax2.set_title('DTI por Default')
Out[175]:
Text(0.5, 1.0, 'DTI por Default')
In [176]:
(loan['dti'] > 40).sum() / (loan['dti']).sum()
Out[176]:
7.220397493054618e-05
In [177]:
loan.groupby('credit_risk')['dti'].median()
Out[177]:
credit_risk
Default       19.66
No Default    17.01
Name: dti, dtype: float64

Caracteristicas Financieras Actuales

Bajo este epígrafe agruparemos todas las variables que describen el historial crediticio del usuario.

  • 'open_acc' : The number of open credit lines in the borrower's credit file.
  • 'revol_bal' : Total credit revolving balance.
  • 'revol_util' : Revolving line utilization rate, or the amount of credit the borrower is using relative to all available revolving credit.
  • 'total_acc' : The total number of credit lines currently in the borrower's credit file.
  • 'acc_now_delinq' : The number of accounts on which the borrower is now delinquent.
  • 'tot_cur_bal' : Total current balance of all accounts.
  • 'total_bal_il' : Total current balance of all installment accounts.
  • 'il_util' : Ratio of total current balance to high credit/credit limit on all install acct.
  • 'max_bal_bc' : Maximum current balance owed on all revolving accounts.
  • 'all_util' : Balance to credit limit on all trades.
  • 'total_rev_hi_lim' : Total revolving high credit/credit limit.
  • 'total_cu_tl' : Number of finance trades.
  • 'avg_cur_bal' : Average current balance of all accounts.
  • 'bc_open_to_buy' : Total open to buy on revolving bankcards.
  • 'bc_util' : Ratio of total current balance to high credit/credit limit for all bankcard accounts.
  • 'delinq_amnt' : The past-due amount owed for the accounts on which the borrower is now delinquent.
  • 'mort_acc' : Number of mortgage accounts.
Open Accounts (Open Acc)

'Open_acc' es el número de líneas de crédito abiertas en el archivo de crédito del prestatario. 'total_acc' es el número total de líneas de crédito actualmente en el archivo de crédito del prestatario. La proporción significa cuántos préstamos tiene el solicitante ahora.

In [178]:
loan['open_acc'].fillna(0, inplace = True) 
In [179]:
loan['acc_ratio'] = loan.open_acc / loan.total_acc
In [180]:
loan['acc_ratio'].fillna(0, inplace = True) 
In [181]:
plot_var('acc_ratio', 'Ratio Open Accounts', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Revolving Balance (Revol Acc)
In [182]:
loan['revol_bal'].isna().sum()
Out[182]:
0
In [183]:
plot_var('revol_bal', 'Revolving Balance', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [184]:
loan["revol_bal_cat"] = 0
loan.loc[loan["revol_bal"]>0,"revol_bal_cat"] = 1
In [185]:
purp_loan= ['revol_bal_cat', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[185]:
credit_risk Default No Default
revol_bal_cat
0 0.42 0.49
1 99.58 99.51
In [186]:
loan.drop(['revol_bal'], 
          axis = 1, inplace = True)
Revolving line utilization (Revol Util)
In [187]:
loan['revol_util'].isnull().sum()
loan['revol_util'].fillna(0, inplace = True)
plot_var('revol_util', 'Revolving line utilization', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [188]:
purp_loan= ['revol_util', 'credit_risk']
cm = sns.light_palette("purple", as_cmap=True)
(round(pd.crosstab(loan[purp_loan[0]], loan[purp_loan[1]], 
                   normalize='columns') * 100,2)).style.background_gradient(cmap = cm)
Out[188]:
credit_risk Default No Default
revol_util
0.0 0.48 0.59
0.01 0 0
0.03 0 0
0.04 0 0
0.05 0 0
0.1 0.06 0.07
0.12 0 0
0.16 0 0
0.2 0.05 0.05
0.3 0.05 0.05
0.4 0.04 0.05
0.46 0 0
0.49 0 0
0.5 0.04 0.04
0.54 0 0
0.6 0.03 0.04
0.7 0.03 0.04
0.75 0 0
0.8 0.03 0.04
0.83 0 0
0.86 0 0
0.9 0.02 0.04
1.0 0.03 0.04
1.1 0.03 0.04
1.2 0.03 0.04
1.3 0.03 0.04
1.4 0.03 0.04
1.5 0.03 0.04
1.6 0.03 0.04
1.7 0.03 0.04
1.8 0.03 0.04
1.88 0 0
1.9 0.02 0.04
2.0 0.03 0.04
2.1 0.03 0.04
2.2 0.03 0.04
2.3 0.03 0.04
2.4 0.03 0.04
2.5 0.03 0.04
2.6 0.02 0.04
2.64 0 0
2.7 0.03 0.04
2.8 0.02 0.04
2.9 0.02 0.04
3.0 0.04 0.04
3.1 0.02 0.04
3.18 0 0
3.2 0.03 0.04
3.3 0.02 0.04
3.4 0.03 0.04
3.5 0.02 0.04
3.6 0.02 0.04
3.7 0.02 0.04
3.8 0.02 0.04
3.9 0.02 0.04
4.0 0.04 0.05
4.1 0.02 0.04
4.2 0.03 0.04
4.3 0.03 0.04
4.4 0.02 0.04
4.5 0.02 0.04
4.6 0.02 0.04
4.7 0.02 0.04
4.8 0.03 0.04
4.85 0 0
4.9 0.03 0.04
5.0 0.03 0.05
5.1 0.03 0.04
5.2 0.03 0.05
5.3 0.03 0.04
5.33 0 0
5.34 0 0
5.4 0.03 0.04
5.5 0.02 0.04
5.6 0.03 0.04
5.7 0.03 0.04
5.79 0 0
5.8 0.04 0.04
5.9 0.02 0.05
6.0 0.03 0.05
6.1 0.03 0.05
6.2 0.03 0.04
6.3 0.03 0.04
6.4 0.03 0.04
6.5 0.02 0.05
6.6 0.03 0.04
6.7 0.03 0.04
6.75 0 0
6.8 0.03 0.04
6.9 0.03 0.05
7.0 0.04 0.05
7.1 0.03 0.04
7.2 0.03 0.05
7.28 0 0
7.3 0.03 0.05
7.4 0.03 0.05
7.43 0 0
7.5 0.03 0.05
7.6 0.03 0.05
7.64 0 0
7.7 0.03 0.05
7.8 0.03 0.05
7.9 0.03 0.06
8.0 0.04 0.06
8.01 0 0
8.1 0.03 0.05
8.2 0.03 0.06
8.3 0.03 0.05
8.4 0.04 0.05
8.46 0 0
8.49 0 0
8.5 0.03 0.04
8.58 0 0
8.6 0.03 0.05
8.7 0.03 0.05
8.8 0.03 0.05
8.9 0.03 0.05
9.0 0.04 0.06
9.1 0.03 0.05
9.2 0.03 0.05
9.3 0.04 0.05
9.34 0 0
9.4 0.03 0.05
9.5 0.03 0.06
9.6 0.02 0.06
9.7 0.04 0.06
9.71 0 0
9.8 0.03 0.05
9.9 0.04 0.06
10.0 0.05 0.06
10.08 0 0
10.1 0.04 0.06
10.17 0 0
10.2 0.03 0.05
10.3 0.03 0.05
10.4 0.03 0.05
10.5 0.04 0.06
10.6 0.03 0.06
10.61 0 0
10.7 0.04 0.06
10.8 0.04 0.06
10.9 0.03 0.06
11.0 0.05 0.06
11.1 0.04 0.06
11.2 0.04 0.06
11.3 0.04 0.06
11.4 0.03 0.06
11.5 0.04 0.06
11.6 0.04 0.06
11.62 0 0
11.63 0 0
11.7 0.04 0.06
11.8 0.04 0.06
11.9 0.03 0.06
12.0 0.05 0.07
12.1 0.05 0.06
12.2 0.04 0.06
12.3 0.04 0.06
12.4 0.04 0.06
12.42 0 0
12.5 0.03 0.06
12.6 0.04 0.06
12.7 0.04 0.06
12.8 0.05 0.07
12.9 0.05 0.06
13.0 0.05 0.07
13.1 0.04 0.06
13.2 0.04 0.06
13.3 0.05 0.06
13.4 0.04 0.06
13.5 0.04 0.06
13.56 0 0
13.6 0.05 0.06
13.7 0.04 0.06
13.8 0.05 0.06
13.9 0.05 0.07
14.0 0.06 0.08
14.1 0.05 0.06
14.2 0.04 0.07
14.3 0.05 0.07
14.4 0.04 0.07
14.5 0.04 0.07
14.6 0.05 0.07
14.7 0.04 0.07
14.8 0.05 0.07
14.9 0.04 0.06
15.0 0.06 0.08
15.1 0.04 0.07
15.2 0.05 0.07
15.3 0.05 0.06
15.4 0.04 0.07
15.5 0.05 0.07
15.6 0.06 0.07
15.7 0.05 0.07
15.8 0.06 0.07
15.9 0.05 0.07
16.0 0.06 0.08
16.02 0 0
16.1 0.06 0.08
16.2 0.05 0.07
16.3 0.06 0.07
16.4 0.04 0.07
16.5 0.06 0.07
16.6 0.05 0.07
16.7 0.06 0.07
16.8 0.06 0.08
16.9 0.05 0.07
17.0 0.07 0.09
17.1 0.06 0.07
17.2 0.05 0.07
17.3 0.05 0.08
17.4 0.05 0.07
17.5 0.05 0.08
17.6 0.05 0.07
17.67 0 0
17.7 0.05 0.08
17.71 0 0
17.78 0 0
17.8 0.05 0.07
17.9 0.05 0.08
18.0 0.08 0.1
18.1 0.05 0.07
18.2 0.06 0.08
18.3 0.05 0.08
18.4 0.06 0.08
18.5 0.06 0.08
18.6 0.06 0.08
18.7 0.07 0.08
18.8 0.06 0.08
18.82 0 0
18.9 0.05 0.08
19.0 0.08 0.1
19.1 0.07 0.08
19.2 0.06 0.08
19.3 0.06 0.08
19.4 0.06 0.08
19.5 0.06 0.08
19.6 0.06 0.08
19.7 0.07 0.08
19.8 0.06 0.08
19.9 0.07 0.08
20.0 0.08 0.1
20.1 0.07 0.08
20.2 0.06 0.08
20.3 0.07 0.09
20.4 0.06 0.08
20.5 0.07 0.09
20.6 0.07 0.08
20.7 0.07 0.08
20.8 0.06 0.08
20.9 0.06 0.09
21.0 0.08 0.1
21.1 0.07 0.08
21.2 0.07 0.09
21.3 0.07 0.08
21.4 0.07 0.08
21.5 0.08 0.09
21.59 0 0
21.6 0.06 0.08
21.7 0.06 0.09
21.72 0 0
21.8 0.07 0.09
21.9 0.07 0.09
21.92 0 0
22.0 0.1 0.11
22.1 0.07 0.09
22.2 0.07 0.09
22.3 0.08 0.09
22.4 0.07 0.09
22.5 0.07 0.09
22.6 0.07 0.09
22.7 0.07 0.09
22.8 0.07 0.09
22.9 0.06 0.09
23.0 0.1 0.11
23.1 0.06 0.09
23.11 0 0
23.2 0.06 0.09
23.3 0.08 0.09
23.4 0.07 0.09
23.5 0.07 0.09
23.6 0.08 0.08
23.7 0.08 0.09
23.8 0.07 0.09
23.9 0.08 0.1
24.0 0.09 0.12
24.1 0.08 0.1
24.2 0.08 0.09
24.3 0.08 0.1
24.4 0.07 0.1
24.5 0.08 0.09
24.6 0.07 0.1
24.63 0 0
24.65 0 0
24.66 0 0
24.7 0.08 0.1
24.8 0.08 0.09
24.89 0 0
24.9 0.09 0.1
25.0 0.09 0.13
25.1 0.08 0.1
25.2 0.08 0.1
25.3 0.07 0.1
25.33 0 0
25.4 0.07 0.1
25.5 0.08 0.1
25.6 0.08 0.09
25.7 0.08 0.1
25.74 0 0
25.8 0.07 0.1
25.9 0.08 0.09
26.0 0.12 0.13
26.1 0.07 0.1
26.2 0.08 0.1
26.3 0.09 0.1
26.32 0 0
26.33 0 0
26.4 0.07 0.1
26.5 0.09 0.1
26.6 0.08 0.11
26.7 0.09 0.1
26.8 0.09 0.1
26.9 0.08 0.1
27.0 0.12 0.13
27.1 0.08 0.11
27.2 0.08 0.1
27.3 0.09 0.1
27.4 0.08 0.1
27.5 0.09 0.11
27.6 0.09 0.11
27.7 0.09 0.1
27.8 0.09 0.1
27.81 0 0
27.9 0.09 0.1
28.0 0.14 0.13
28.1 0.08 0.11
28.2 0.08 0.1
28.3 0.09 0.11
28.4 0.1 0.11
28.41 0 0
28.5 0.09 0.1
28.6 0.1 0.1
28.7 0.09 0.11
28.8 0.09 0.11
28.9 0.08 0.1
29.0 0.12 0.14
29.1 0.09 0.11
29.2 0.09 0.11
29.3 0.09 0.11
29.4 0.09 0.12
29.5 0.09 0.11
29.53 0 0
29.6 0.1 0.11
29.7 0.09 0.11
29.77 0 0
29.8 0.1 0.11
29.9 0.1 0.12
30.0 0.14 0.14
30.1 0.09 0.11
30.19 0 0
30.2 0.09 0.11
30.3 0.09 0.11
30.4 0.1 0.11
30.5 0.1 0.12
30.6 0.09 0.11
30.7 0.09 0.12
30.8 0.1 0.11
30.9 0.09 0.11
31.0 0.14 0.15
31.1 0.11 0.11
31.2 0.1 0.12
31.3 0.09 0.12
31.4 0.09 0.11
31.5 0.1 0.12
31.6 0.1 0.12
31.7 0.11 0.11
31.8 0.09 0.11
31.9 0.1 0.12
32.0 0.15 0.15
32.04 0 0
32.1 0.1 0.11
32.2 0.1 0.11
32.3 0.1 0.12
32.4 0.1 0.12
32.5 0.1 0.11
32.6 0.11 0.12
32.7 0.11 0.12
32.71 0 0
32.8 0.1 0.11
32.9 0.1 0.11
33.0 0.16 0.16
33.1 0.11 0.12
33.14 0 0
33.2 0.11 0.11
33.26 0 0
33.29 0 0
33.3 0.11 0.12
33.39 0 0
33.4 0.12 0.12
33.5 0.1 0.12
33.6 0.12 0.12
33.7 0.1 0.12
33.8 0.11 0.12
33.9 0.11 0.11
34.0 0.15 0.16
34.1 0.1 0.12
34.2 0.11 0.12
34.3 0.11 0.12
34.4 0.11 0.12
34.5 0.13 0.13
34.6 0.12 0.12
34.7 0.11 0.12
34.8 0.11 0.13
34.89 0 0
34.9 0.1 0.12
35.0 0.17 0.16
35.1 0.13 0.12
35.2 0.11 0.13
35.3 0.11 0.12
35.4 0.11 0.13
35.5 0.11 0.12
35.6 0.11 0.12
35.7 0.12 0.13
35.8 0.11 0.12
35.9 0.11 0.12
36.0 0.15 0.16
36.1 0.12 0.12
36.2 0.11 0.12
36.3 0.1 0.12
36.4 0.12 0.12
36.5 0.11 0.13
36.6 0.11 0.13
36.7 0.12 0.13
36.78 0 0
36.8 0.1 0.13
36.88 0 0
36.9 0.12 0.13
36.94 0 0
37.0 0.17 0.17
37.1 0.12 0.12
37.2 0.11 0.13
37.3 0.13 0.12
37.4 0.12 0.12
37.5 0.11 0.12
37.6 0.11 0.13
37.63 0 0
37.7 0.1 0.13
37.73 0 0
37.8 0.11 0.13
37.9 0.12 0.13
38.0 0.16 0.17
38.1 0.11 0.12
38.2 0.14 0.13
38.3 0.12 0.13
38.4 0.12 0.13
38.5 0.12 0.13
38.6 0.13 0.13
38.7 0.11 0.13
38.77 0 0
38.8 0.14 0.13
38.9 0.12 0.13
39.0 0.18 0.17
39.1 0.12 0.12
39.2 0.12 0.13
39.3 0.12 0.13
39.4 0.12 0.13
39.5 0.12 0.12
39.6 0.12 0.13
39.7 0.13 0.12
39.8 0.11 0.12
39.9 0.12 0.12
39.95 0 0
40.0 0.17 0.17
40.1 0.12 0.13
40.2 0.11 0.13
40.3 0.11 0.12
40.4 0.12 0.12
40.5 0.13 0.13
40.6 0.12 0.12
40.7 0.14 0.13
40.8 0.12 0.13
40.9 0.12 0.13
41.0 0.18 0.17
41.1 0.12 0.13
41.2 0.12 0.13
41.3 0.13 0.13
41.4 0.12 0.13
41.5 0.13 0.12
41.6 0.11 0.13
41.7 0.13 0.13
41.8 0.12 0.12
41.85 0 0
41.9 0.12 0.12
42.0 0.2 0.18
42.1 0.13 0.13
42.2 0.11 0.12
42.3 0.12 0.13
42.4 0.11 0.13
42.5 0.13 0.13
42.6 0.13 0.13
42.7 0.14 0.13
42.8 0.13 0.13
42.9 0.13 0.13
43.0 0.2 0.18
43.1 0.13 0.13
43.2 0.13 0.13
43.3 0.13 0.12
43.38 0 0
43.4 0.12 0.13
43.5 0.14 0.13
43.6 0.12 0.13
43.61 0 0
43.7 0.13 0.13
43.8 0.12 0.13
43.9 0.13 0.13
44.0 0.21 0.18
44.1 0.12 0.13
44.2 0.14 0.13
44.3 0.13 0.14
44.4 0.12 0.13
44.5 0.12 0.13
44.6 0.12 0.13
44.7 0.12 0.13
44.8 0.14 0.13
44.9 0.13 0.13
45.0 0.19 0.18
45.1 0.13 0.13
45.2 0.14 0.13
45.3 0.14 0.13
45.4 0.12 0.13
45.5 0.13 0.14
45.6 0.13 0.12
45.7 0.13 0.13
45.8 0.13 0.13
45.9 0.14 0.13
46.0 0.19 0.18
46.1 0.13 0.13
46.2 0.13 0.14
46.3 0.14 0.13
46.4 0.12 0.13
46.5 0.12 0.13
46.6 0.13 0.14
46.7 0.14 0.14
46.74 0 0
46.8 0.13 0.13
46.9 0.13 0.13
47.0 0.2 0.18
47.1 0.15 0.13
47.2 0.14 0.14
47.3 0.13 0.14
47.36 0 0
47.4 0.13 0.13
47.5 0.13 0.13
47.6 0.14 0.13
47.7 0.14 0.14
47.8 0.13 0.14
47.9 0.13 0.13
48.0 0.22 0.19
48.1 0.14 0.13
48.2 0.15 0.13
48.3 0.13 0.14
48.4 0.14 0.14
48.5 0.14 0.13
48.6 0.14 0.13
48.7 0.13 0.13
48.8 0.13 0.13
48.9 0.14 0.14
49.0 0.22 0.18
49.1 0.13 0.14
49.2 0.13 0.13
49.3 0.13 0.13
49.4 0.14 0.14
49.5 0.14 0.14
49.6 0.14 0.14
49.63 0 0
49.69 0 0
49.7 0.14 0.13
49.8 0.14 0.13
49.9 0.14 0.14
50.0 0.21 0.19
50.1 0.13 0.14
50.2 0.13 0.13
50.3 0.14 0.13
50.4 0.13 0.13
50.5 0.14 0.13
50.6 0.13 0.13
50.7 0.14 0.14
50.8 0.13 0.13
50.9 0.14 0.14
51.0 0.21 0.18
51.1 0.15 0.13
51.2 0.13 0.13
51.3 0.12 0.13
51.4 0.13 0.14
51.5 0.13 0.14
51.6 0.14 0.13
51.7 0.14 0.14
51.8 0.13 0.13
51.9 0.14 0.13
52.0 0.23 0.18
52.1 0.14 0.13
52.2 0.14 0.14
52.3 0.15 0.13
52.4 0.13 0.14
52.5 0.14 0.13
52.58 0 0
52.6 0.14 0.14
52.7 0.15 0.13
52.8 0.14 0.14
52.9 0.13 0.14
53.0 0.22 0.19
53.1 0.14 0.14
53.2 0.14 0.13
53.3 0.14 0.14
53.4 0.14 0.13
53.5 0.15 0.14
53.6 0.14 0.14
53.7 0.14 0.13
53.8 0.15 0.13
53.9 0.14 0.13
54.0 0.23 0.19
54.1 0.15 0.13
54.2 0.14 0.14
54.22 0 0
54.3 0.16 0.13
54.4 0.14 0.13
54.5 0.13 0.14
54.6 0.13 0.14
54.7 0.14 0.14
54.8 0.14 0.13
54.9 0.13 0.14
55.0 0.22 0.18
55.1 0.14 0.14
55.2 0.14 0.14
55.3 0.14 0.13
55.4 0.14 0.14
55.5 0.14 0.14
55.6 0.14 0.13
55.7 0.14 0.13
55.8 0.13 0.13
55.9 0.14 0.13
56.0 0.22 0.18
56.1 0.14 0.13
56.2 0.13 0.14
56.26 0 0
56.3 0.14 0.14
56.4 0.13 0.14
56.5 0.14 0.13
56.6 0.15 0.13
56.7 0.15 0.13
56.8 0.15 0.13
56.9 0.13 0.14
57.0 0.23 0.19
57.1 0.14 0.13
57.2 0.16 0.13
57.3 0.13 0.14
57.4 0.15 0.13
57.5 0.14 0.14
57.56 0 0
57.6 0.14 0.13
57.7 0.15 0.13
57.8 0.15 0.13
57.9 0.14 0.13
58.0 0.22 0.19
58.1 0.14 0.13
58.19 0 0
58.2 0.14 0.13
58.3 0.15 0.13
58.4 0.14 0.13
58.5 0.13 0.13
58.6 0.14 0.13
58.7 0.16 0.13
58.77 0 0
58.8 0.14 0.13
58.9 0.15 0.13
59.0 0.23 0.19
59.1 0.15 0.13
59.2 0.14 0.13
59.3 0.14 0.13
59.4 0.14 0.13
59.5 0.14 0.14
59.6 0.14 0.13
59.7 0.14 0.13
59.8 0.14 0.13
59.9 0.15 0.13
60.0 0.21 0.19
60.1 0.14 0.13
60.2 0.15 0.14
60.3 0.15 0.12
60.4 0.15 0.14
60.5 0.14 0.13
60.6 0.14 0.12
60.69 0 0
60.7 0.13 0.14
60.8 0.14 0.13
60.9 0.13 0.12
61.0 0.23 0.18
61.1 0.14 0.13
61.2 0.15 0.13
61.3 0.14 0.13
61.4 0.13 0.13
61.5 0.13 0.13
61.6 0.15 0.13
61.7 0.14 0.13
61.8 0.12 0.13
61.9 0.15 0.12
62.0 0.22 0.18
62.1 0.14 0.12
62.2 0.14 0.13
62.3 0.14 0.13
62.31 0 0
62.4 0.14 0.13
62.5 0.13 0.12
62.6 0.13 0.13
62.7 0.14 0.13
62.8 0.14 0.13
62.9 0.14 0.13
63.0 0.21 0.18
63.1 0.13 0.13
63.2 0.14 0.13
63.3 0.13 0.12
63.4 0.15 0.12
63.5 0.14 0.12
63.6 0.13 0.13
63.7 0.13 0.13
63.8 0.13 0.12
63.9 0.14 0.13
64.0 0.21 0.17
64.1 0.14 0.12
64.2 0.13 0.12
64.3 0.13 0.13
64.4 0.15 0.12
64.5 0.14 0.12
64.6 0.14 0.13
64.7 0.13 0.12
64.8 0.13 0.12
64.9 0.13 0.12
65.0 0.23 0.17
65.1 0.13 0.12
65.2 0.13 0.13
65.3 0.13 0.13
65.4 0.13 0.12
65.5 0.14 0.12
65.6 0.14 0.12
65.7 0.14 0.12
65.8 0.13 0.12
65.9 0.13 0.12
66.0 0.21 0.17
66.1 0.13 0.13
66.2 0.14 0.12
66.3 0.14 0.12
66.4 0.11 0.12
66.5 0.13 0.12
66.6 0.14 0.12
66.7 0.14 0.13
66.8 0.14 0.12
66.9 0.13 0.12
67.0 0.21 0.16
67.1 0.14 0.12
67.2 0.14 0.12
67.3 0.14 0.13
67.4 0.14 0.12
67.5 0.14 0.12
67.6 0.14 0.12
67.7 0.12 0.12
67.8 0.14 0.12
67.9 0.13 0.12
68.0 0.22 0.17
68.1 0.13 0.12
68.2 0.12 0.12
68.3 0.12 0.11
68.4 0.14 0.12
68.5 0.13 0.12
68.6 0.13 0.12
68.7 0.14 0.12
68.8 0.13 0.12
68.9 0.14 0.12
69.0 0.2 0.16
69.1 0.13 0.12
69.14 0 0
69.2 0.13 0.12
69.3 0.12 0.12
69.4 0.15 0.12
69.5 0.13 0.12
69.6 0.13 0.12
69.7 0.12 0.11
69.8 0.11 0.12
69.9 0.13 0.12
69.98 0 0
70.0 0.2 0.16
70.1 0.13 0.11
70.2 0.13 0.12
70.26 0 0
70.3 0.12 0.12
70.4 0.12 0.11
70.5 0.13 0.11
70.6 0.13 0.12
70.7 0.12 0.12
70.8 0.13 0.12
70.9 0.12 0.12
70.94 0 0
71.0 0.19 0.16
71.1 0.13 0.11
71.2 0.13 0.11
71.3 0.11 0.11
71.4 0.11 0.12
71.5 0.12 0.11
71.6 0.13 0.12
71.7 0.13 0.11
71.8 0.14 0.12
71.9 0.14 0.11
72.0 0.2 0.16
72.1 0.11 0.12
72.2 0.13 0.11
72.3 0.14 0.11
72.4 0.12 0.11
72.5 0.11 0.11
72.6 0.13 0.11
72.7 0.12 0.11
72.8 0.14 0.11
72.9 0.12 0.11
73.0 0.21 0.16
73.1 0.11 0.11
73.2 0.11 0.11
73.3 0.13 0.1
73.4 0.11 0.12
73.5 0.12 0.11
73.6 0.13 0.11
73.7 0.11 0.11
73.8 0.12 0.11
73.9 0.11 0.11
74.0 0.2 0.15
74.1 0.12 0.11
74.2 0.11 0.11
74.3 0.12 0.11
74.4 0.12 0.11
74.5 0.12 0.11
74.6 0.11 0.1
74.7 0.11 0.1
74.8 0.12 0.1
74.9 0.12 0.1
75.0 0.2 0.15
75.1 0.11 0.1
75.2 0.12 0.1
75.3 0.12 0.1
75.4 0.13 0.1
75.5 0.12 0.1
75.6 0.11 0.1
75.7 0.12 0.11
75.8 0.12 0.1
75.9 0.11 0.11
76.0 0.19 0.15
76.1 0.11 0.1
76.2 0.12 0.1
76.3 0.11 0.1
76.4 0.12 0.1
76.5 0.1 0.11
76.6 0.12 0.11
76.7 0.1 0.1
76.8 0.11 0.1
76.9 0.12 0.1
77.0 0.18 0.15
77.1 0.12 0.1
77.2 0.11 0.1
77.3 0.11 0.1
77.4 0.12 0.1
77.5 0.11 0.1
77.6 0.12 0.1
77.63 0 0
77.7 0.11 0.1
77.8 0.11 0.09
77.9 0.12 0.1
78.0 0.19 0.14
78.1 0.11 0.1
78.2 0.11 0.1
78.3 0.11 0.1
78.4 0.12 0.1
78.5 0.1 0.1
78.6 0.1 0.1
78.7 0.11 0.09
78.8 0.12 0.1
78.9 0.1 0.09
79.0 0.19 0.14
79.1 0.11 0.09
79.2 0.11 0.1
79.3 0.1 0.1
79.4 0.11 0.1
79.5 0.1 0.09
79.6 0.09 0.1
79.7 0.11 0.1
79.8 0.12 0.09
79.9 0.12 0.1
80.0 0.19 0.13
80.1 0.09 0.09
80.2 0.11 0.1
80.3 0.1 0.09
80.4 0.1 0.09
80.5 0.1 0.09
80.6 0.11 0.09
80.7 0.1 0.09
80.8 0.1 0.09
80.9 0.09 0.09
81.0 0.17 0.13
81.1 0.11 0.09
81.2 0.09 0.09
81.3 0.09 0.09
81.31 0 0
81.4 0.1 0.09
81.5 0.1 0.09
81.6 0.1 0.09
81.7 0.11 0.08
81.8 0.1 0.08
81.9 0.11 0.09
82.0 0.17 0.13
82.1 0.1 0.09
82.2 0.1 0.09
82.3 0.11 0.09
82.4 0.1 0.09
82.5 0.1 0.09
82.6 0.1 0.09
82.7 0.09 0.09
82.8 0.1 0.09
82.9 0.09 0.09
83.0 0.17 0.13
83.1 0.09 0.09
83.2 0.1 0.08
83.3 0.11 0.09
83.4 0.1 0.09
83.5 0.1 0.08
83.6 0.09 0.09
83.7 0.1 0.09
83.8 0.1 0.09
83.9 0.1 0.08
84.0 0.16 0.13
84.1 0.1 0.08
84.2 0.09 0.08
84.3 0.1 0.08
84.4 0.09 0.08
84.5 0.09 0.09
84.6 0.09 0.09
84.7 0.09 0.08
84.8 0.1 0.08
84.9 0.09 0.08
85.0 0.15 0.12
85.1 0.1 0.08
85.2 0.09 0.08
85.3 0.1 0.08
85.4 0.09 0.08
85.5 0.08 0.08
85.6 0.09 0.08
85.7 0.08 0.08
85.8 0.09 0.08
85.9 0.08 0.08
86.0 0.14 0.11
86.1 0.08 0.08
86.2 0.08 0.08
86.3 0.08 0.07
86.4 0.09 0.08
86.5 0.09 0.08
86.6 0.08 0.08
86.7 0.09 0.08
86.8 0.08 0.08
86.9 0.08 0.08
87.0 0.15 0.11
87.1 0.09 0.07
87.2 0.09 0.07
87.3 0.08 0.08
87.4 0.09 0.07
87.5 0.09 0.07
87.6 0.09 0.07
87.7 0.08 0.08
87.8 0.08 0.07
87.9 0.09 0.07
88.0 0.14 0.11
88.1 0.08 0.07
88.2 0.07 0.07
88.3 0.09 0.07
88.4 0.07 0.07
88.48 0 0
88.5 0.08 0.07
88.6 0.08 0.07
88.7 0.08 0.07
88.8 0.09 0.07
88.9 0.07 0.07
89.0 0.13 0.1
89.1 0.08 0.07
89.2 0.08 0.07
89.3 0.1 0.07
89.4 0.09 0.07
89.5 0.09 0.07
89.6 0.08 0.07
89.7 0.07 0.06
89.8 0.08 0.06
89.9 0.08 0.07
90.0 0.12 0.1
90.1 0.07 0.07
90.2 0.07 0.07
90.3 0.08 0.07
90.4 0.07 0.06
90.5 0.07 0.06
90.6 0.08 0.06
90.7 0.08 0.06
90.8 0.08 0.07
90.9 0.07 0.07
91.0 0.14 0.09
91.1 0.08 0.06
91.2 0.07 0.06
91.3 0.08 0.06
91.4 0.06 0.06
91.5 0.07 0.06
91.6 0.07 0.06
91.7 0.08 0.06
91.8 0.07 0.06
91.9 0.07 0.06
92.0 0.13 0.09
92.1 0.07 0.06
92.2 0.08 0.06
92.3 0.07 0.06
92.4 0.07 0.06
92.5 0.07 0.06
92.6 0.07 0.06
92.7 0.08 0.06
92.8 0.07 0.07
92.9 0.07 0.06
93.0 0.11 0.09
93.1 0.07 0.06
93.2 0.07 0.06
93.3 0.07 0.06
93.4 0.07 0.06
93.5 0.07 0.06
93.6 0.07 0.06
93.7 0.07 0.06
93.8 0.06 0.06
93.9 0.07 0.06
94.0 0.11 0.08
94.1 0.07 0.06
94.2 0.07 0.06
94.3 0.07 0.06
94.4 0.06 0.06
94.46 0 0
94.5 0.07 0.05
94.6 0.07 0.06
94.7 0.07 0.06
94.8 0.07 0.05
94.9 0.06 0.06
95.0 0.1 0.08
95.1 0.06 0.05
95.2 0.07 0.06
95.3 0.06 0.06
95.4 0.06 0.05
95.5 0.06 0.05
95.6 0.05 0.05
95.7 0.06 0.05
95.8 0.06 0.05
95.9 0.06 0.05
96.0 0.1 0.07
96.1 0.06 0.05
96.2 0.06 0.05
96.3 0.06 0.05
96.4 0.06 0.05
96.5 0.07 0.05
96.6 0.06 0.05
96.7 0.05 0.05
96.8 0.06 0.05
96.9 0.06 0.05
97.0 0.09 0.07
97.1 0.06 0.05
97.2 0.06 0.05
97.3 0.06 0.05
97.4 0.06 0.05
97.5 0.05 0.05
97.6 0.06 0.05
97.7 0.06 0.04
97.8 0.06 0.05
97.9 0.06 0.04
98.0 0.08 0.06
98.1 0.05 0.04
98.2 0.05 0.04
98.3 0.05 0.04
98.4 0.05 0.04
98.5 0.05 0.04
98.6 0.05 0.04
98.7 0.05 0.04
98.8 0.05 0.04
98.9 0.04 0.04
99.0 0.08 0.05
99.1 0.04 0.04
99.2 0.04 0.03
99.3 0.04 0.03
99.4 0.04 0.03
99.5 0.04 0.03
99.6 0.03 0.03
99.7 0.03 0.03
99.8 0.03 0.02
99.9 0.03 0.02
100.0 0.05 0.03
100.1 0.02 0.02
100.2 0.02 0.02
100.3 0.02 0.01
100.4 0.02 0.01
100.5 0.02 0.02
100.6 0.02 0.01
100.7 0.02 0.01
100.8 0.02 0.01
100.9 0.01 0.01
101.0 0.03 0.02
101.1 0.01 0.01
101.2 0.01 0.01
101.3 0.01 0.01
101.4 0.01 0.01
101.5 0.01 0.01
101.6 0.01 0.01
101.7 0.01 0.01
101.8 0.01 0.01
101.9 0.01 0.01
102.0 0.02 0.01
102.1 0 0
102.2 0.01 0
102.3 0.01 0
102.4 0 0
102.5 0 0
102.6 0 0
102.7 0 0
102.8 0 0
102.9 0 0
103.0 0.01 0
103.1 0 0
103.2 0 0
103.3 0 0
103.4 0 0
103.5 0 0
103.6 0 0
103.7 0 0
103.8 0 0
103.9 0 0
104.0 0 0
104.1 0 0
104.2 0 0
104.3 0 0
104.4 0 0
104.5 0 0
104.6 0 0
104.7 0 0
104.8 0 0
104.9 0 0
105.0 0 0
105.1 0 0
105.2 0 0
105.3 0 0
105.4 0 0
105.5 0 0
105.6 0 0
105.7 0 0
105.8 0 0
105.9 0 0
106.0 0 0
106.1 0 0
106.2 0 0
106.3 0 0
106.4 0 0
106.5 0 0
106.6 0 0
106.7 0 0
106.8 0 0
106.9 0 0
107.0 0 0
107.1 0 0
107.2 0 0
107.3 0 0
107.4 0 0
107.5 0 0
107.6 0 0
107.7 0 0
107.8 0 0
107.9 0 0
108.0 0 0
108.1 0 0
108.2 0 0
108.3 0 0
108.4 0 0
108.5 0 0
108.6 0 0
108.7 0 0
108.8 0 0
108.9 0 0
109.0 0 0
109.1 0 0
109.2 0 0
109.3 0 0
109.4 0 0
109.5 0 0
109.6 0 0
109.7 0 0
109.8 0 0
109.9 0 0
110.0 0 0
110.1 0 0
110.2 0 0
110.3 0 0
110.4 0 0
110.5 0 0
110.6 0 0
110.7 0 0
110.8 0 0
110.9 0 0
111.0 0 0
111.1 0 0
111.2 0 0
111.3 0 0
111.4 0 0
111.5 0 0
111.6 0 0
111.7 0 0
111.8 0 0
111.9 0 0
112.0 0 0
112.1 0 0
112.2 0 0
112.3 0 0
112.4 0 0
112.5 0 0
112.6 0 0
112.7 0 0
112.8 0 0
112.9 0 0
113.0 0 0
113.1 0 0
113.2 0 0
113.3 0 0
113.4 0 0
113.5 0 0
113.6 0 0
113.7 0 0
113.8 0 0
113.9 0 0
114.0 0 0
114.1 0 0
114.2 0 0
114.4 0 0
114.5 0 0
114.6 0 0
114.7 0 0
114.8 0 0
114.9 0 0
115.0 0 0
115.1 0 0
115.3 0 0
115.4 0 0
115.5 0 0
115.6 0 0
115.7 0 0
115.8 0 0
116.0 0 0
116.1 0 0
116.2 0 0
116.3 0 0
116.4 0 0
116.5 0 0
116.8 0 0
117.1 0 0
117.2 0 0
117.4 0 0
117.5 0 0
117.6 0 0
117.7 0 0
117.9 0 0
118.0 0 0
118.1 0 0
118.2 0 0
118.4 0 0
118.6 0 0
118.9 0 0
119.0 0 0
119.1 0 0
119.2 0 0
119.4 0 0
119.6 0 0
119.7 0 0
120.0 0 0
120.2 0 0
120.5 0 0
120.8 0 0
120.9 0 0
121.0 0 0
121.1 0 0
121.4 0 0
121.7 0 0
122.1 0 0
122.2 0 0
122.4 0 0
122.5 0 0
122.7 0 0
122.8 0 0
123.0 0 0
123.2 0 0
123.3 0 0
123.5 0 0
123.9 0 0
124.5 0 0
124.7 0 0
125.0 0 0
125.2 0 0
125.3 0 0
125.7 0 0
126.1 0 0
126.2 0 0
126.3 0 0
126.4 0 0
127.0 0 0
127.1 0 0
127.3 0 0
127.4 0 0
127.6 0 0
128.0 0 0
128.1 0 0
128.6 0 0
128.7 0 0
129.4 0 0
129.5 0 0
129.6 0 0
130.1 0 0
130.2 0 0
130.4 0 0
131.0 0 0
131.8 0 0
132.1 0 0
132.2 0 0
132.5 0 0
132.7 0 0
132.9 0 0
133.1 0 0
134.1 0 0
134.3 0 0
134.5 0 0
136.0 0 0
136.1 0 0
136.7 0 0
137.2 0 0
137.8 0 0
137.9 0 0
138.9 0 0
139.7 0 0
140.4 0 0
141.1 0 0
143.6 0 0
145.0 0 0
145.8 0 0
146.1 0 0
148.0 0 0
150.7 0 0
152.5 0 0
152.6 0 0
152.7 0 0
153.0 0 0
153.7 0 0
154.9 0 0
155.3 0 0
156.3 0 0
162.0 0 0
165.8 0 0
172.0 0 0
177.7 0 0
180.3 0 0
182.8 0 0
184.6 0 0
193.0 0 0
366.6 0 0
892.3 0 0
Total Number of Credit Lines (Total Acc)
In [189]:
loan['total_acc'].isna().sum()
loan['total_acc'].fillna(0, inplace = True)
plot_var('total_acc', 'Total Number of Credit Lines', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Number of satisfactory accounts (Num sats)
In [190]:
loan['num_sats'].isna().sum()
loan['num_sats'].fillna(0, inplace = True)
The number of accounts on which the borrower is now delinquent. (Acc Now Delinq)
In [191]:
loan['acc_now_delinq'].isna().sum()
loan['acc_now_delinq'].fillna(0, inplace = True)
plot_var('acc_now_delinq', 'Number of satisfactory accounts', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Total current balance of all accounts (Total Cur Bal)
In [192]:
loan['tot_cur_bal'].isna().sum()
loan['tot_cur_bal'].fillna(0, inplace = True)
plot_var('tot_cur_bal', 'Total current balance of all accounts', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Total current balance of all installment accounts (Total Bal Il)
In [193]:
loan['total_bal_il'].isna().sum()
loan['total_bal_il'].fillna(0, inplace = True)
plot_var('total_bal_il', 'Total current balance of all installment accounts', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Ratio of total current balance to high credit/credit limit on all install acct (Il Util)
In [194]:
loan['il_util'].isna().sum()
loan['il_util'].fillna(0, inplace = True)
plot_var('il_util', 'High Credit/Credit Limit', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Maximum current balance owed on all revolving accounts (Max Bal BC)
In [195]:
loan['max_bal_bc'].isna().sum()
loan['max_bal_bc'].fillna(0, inplace = True)
plot_var('max_bal_bc', 'Maximum current balance owed on all revolving accounts', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Balance to credit limit on all trades (All Util)
In [196]:
loan['all_util'].isna().sum()
loan['all_util'].fillna(0, inplace = True)
plot_var('all_util', 'Balance to credit limit on all trades', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Total revolving high Limit (Total Rev Hi Lim)
In [197]:
loan['total_rev_hi_lim'].isna().sum()
loan['total_rev_hi_lim'].fillna(0, inplace = True)
plot_var('total_rev_hi_lim', 'Total revolving high Limit', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [198]:
loan.drop(['total_rev_hi_lim'],axis = 1, inplace = True)
Number of finance trades (Total Cu Tl)
In [199]:
loan['total_cu_tl'].isna().sum()
loan['total_cu_tl'].fillna(0, inplace = True)
plot_var('total_cu_tl', 'Number of finance trades', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Average current balance of all accounts (Avg Cur Bal)
In [200]:
loan['avg_cur_bal'].isna().sum()
loan['avg_cur_bal'].fillna(0, inplace = True)
plot_var('avg_cur_bal', 'Average current balance of all accounts', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Total open to buy on revolving bankcards. (Bc Open To Buy)
In [201]:
loan['bc_open_to_buy'].isna().sum()
loan['bc_open_to_buy'].fillna(0, inplace = True)
plot_var('bc_open_to_buy', 'Total open to buy on revolving bankcards', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Ratio of total current balance to high credit/credit limit for all bankcard accounts. (Bc Util)
In [202]:
loan['bc_util'].isna().sum()
loan['bc_util'].fillna(0, inplace = True)
plot_var('bc_util', 'High credit/Credit limit on all accounts', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
The past-due amount owed for the accounts on which the borrower is now delinquent. (Delinq Amnt)
In [203]:
loan['delinq_amnt'].isna().sum()
loan['delinq_amnt'].fillna(0, inplace = True)
plot_var('delinq_amnt', 'past-due amount owed for the delinquent accounts', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Mortgage accounts
In [204]:
loan['mort_acc'].isna().sum()
loan['mort_acc'].fillna(0, inplace = True)
Number of mortgage accounts. (Mort Acc)
In [205]:
loan.drop(['total_acc','total_bal_il','max_bal_bc','all_util',
                    'total_cu_tl'],1, inplace=True)
loan.shape
Out[205]:
(1283143, 91)

Indicadores de Crédito

In [206]:
matrix_corr(loan[['tot_hi_cred_lim','total_bal_ex_mort',
                 'total_bc_limit','total_il_high_credit_limit']]
           , mirror=False)

Como se esta considerando la variable que incluye todos los saldos, esta variable tiene información redundante.

In [207]:
loan.drop(['total_bal_ex_mort'], axis = 1, inplace = True)

Como se puede observar, las variables recogidas bajo este epígrafe presentan una alta correlación, debido a que recogen información similar. Prescindiremos de la información redundante mediante la inclusión de una sola variable que aglutine toda la información.

Total high credit/credit limit
In [208]:
loan['tot_hi_cred_lim'].isnull().sum()
Out[208]:
70276
In [209]:
loan['tot_hi_cred_lim'].fillna(0, inplace = True)
In [210]:
plot_var('tot_hi_cred_lim', 'High credit/credit limit', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Prescindimos de esta variable por no tener poder discriminante.

In [211]:
loan.drop(['tot_hi_cred_lim'], axis = 1, inplace = True)
Total credit balance excluding mortgage
In [212]:
loan['total_bc_limit'].isna().sum()
Out[212]:
50030
In [213]:
loan['total_bc_limit'].fillna(0,inplace = True)
In [214]:
plot_var('total_bc_limit', 'Total credit balance w/o mortgage', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
Total bankcard high credit/credit limit
In [215]:
loan['total_bc_limit'].isna().sum()
Out[215]:
0
In [216]:
loan['total_bc_limit'].fillna(0, inplace = True)
In [217]:
plot_var('total_bc_limit', 'Total bankcard high credit/credit limit', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [218]:
loan.drop(['total_bc_limit'],axis = 1, inplace = True)
Total installment high credit/credit limit
In [219]:
loan['total_il_high_credit_limit'].fillna(0, inplace = True)
In [220]:
plot_var('total_il_high_credit_limit', 'Total installment high credit/credit limit', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Rendimiento del Préstamo

Se trata de información del desempeño del préstamo y estos datos no se obtienen al entregar el préstamo sino después.

In [221]:
loan_perf_lst = ['out_prncp','out_prncp_inv','total_pymnt','total_pymnt_inv',
                    'total_rec_prncp','total_rec_int','total_rec_late_fee','recoveries',
                    'collection_recovery_fee','last_pymnt_d','last_pymnt_amnt',
                   'next_pymnt_d','last_credit_pull_d']
loan.drop(loan_perf_lst,1, inplace=True)

'Months since'

Bajo este epígrafe agrupamos todas las variables que hacen referencia al tiempo que ha pasado desde un evento determinado, ya que les daremos un tratamiento similar. Estas variables son:

  • 'mths_since_recent_bc': months since most recent bankcard account opened.
  • 'mths_since_recent_bc_dlq': months since most recent bankcard delinquency
  • 'mths_since_recent_inq': months since most recent inquiry.
  • 'mths_since_recent_revol_delinq': months since most recent revolving delinquency.

Calculamos la matriz de correlación. Observamos que existe una alta correlación entre 'mths_since_bc_dlq' y 'mths_since_recent_revol_delinq'. Dado que contienen información similar, prescindiremos de una de las variables.

In [222]:
matrix_corr(loan[['mths_since_recent_bc','mths_since_recent_bc_dlq',
                 'mths_since_recent_inq','mths_since_recent_revol_delinq']]
           , mirror=False)
Months since most recent bankcard account opened.

Suponemos que los NA señalan las personas que no tienen ninguna cuenta abierta, por lo que les imputamos un 0.

In [223]:
loan['mths_since_recent_bc'].isna().sum()
Out[223]:
61975
In [224]:
loan['mths_since_recent_bc'].fillna(0, inplace = True)
plot_var('mths_since_recent_bc', 'Months since most recent bankcard account opened.', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)
In [225]:
loan.drop(['mths_since_recent_bc'], axis=1, inplace = True)
Months since most recent bankcard delinquency
In [226]:
loan['mths_since_recent_bc_dlq'].isna().sum()
Out[226]:
979043
In [227]:
loan['mths_since_recent_bc_dlq'].fillna(0, inplace = True) 
In [228]:
plot_var('mths_since_recent_bc_dlq', 'Months since most recent bankcard delinquency', continuous= True)
C:\Users\Marina\Anaconda3\lib\site-packages\seaborn\axisgrid.py:230: UserWarning: The `size` paramter has been renamed to `height`; please update your code.
  warnings.warn(msg, UserWarning)

Se decide prescindir de esta variable.

In [229]:
loan.drop(['mths_since_recent_bc_dlq'], axis = 1, inplace = True)
Months since most recent inquiry.

Esta variable nos genera dudas sobre su relevancia. Una 'inquiry' es una comprobación que realiza Lending Club sobre las operaciones realizadas por el prestatario. Estas pueden ser 'soft' (en operaciones menores, que no afectan al credit score) o 'hard' (en operaciones de mayor riesgo, como hipotecas o líneas de crédito extra). Las soft inquiries no afectan al credit score. Por el contrario, una hard inquiry puede tener un mínimo impacto sobre el credit score del prestamista (1 a 5 puntos). Sólo la acumulación de hard inquiries tienen un impacto real. https://help.lendingclub.com/hc/en-us/articles/213803238-Understanding-your-credit-score Dado que esta variable no distingue entre soft y hard inquiries, consideramos que la inclusión de esta variable podría distorsionar el resultado, por lo que se decide prescindir de ella.

In [230]:
loan.drop(['mths_since_recent_inq'], axis=1, inplace = True)
Months since most recent revolving delinquency.

Prescindimos de esta variable ya que, como se avanzó anteriormente, está altamente relacionada con 'Months since most recent bankcard delinquency', variable más amplia que incluye esta información.

In [231]:
loan.drop(['mths_since_recent_revol_delinq'], axis=1, inplace = True)

Hardship plan

fuente: https://www.debt.org/credit/loans/personal/lending-club-review/

Lending Club ofrece a los usuarios con dificultades económicas un 'hardship plan' (plan de dificultades). Este plan consiste en el pago únicamente de los intereses devengados durante 3 meses. Nos planteamos si la concesión de un plan de dificultades, en algún momento (y no solo en la actualidad) es determinante o presenta una mayor incidencia en relación con la probabilidad de hacer un impago.

In [232]:
hardship = loan[['hardship_flag', 'hardship_type', 'hardship_reason', 'hardship_status',
       'deferral_term', 'hardship_amount', 'hardship_start_date',
       'hardship_end_date', 'payment_plan_start_date', 'hardship_length',
       'hardship_dpd', 'hardship_loan_status',
       'orig_projected_additional_accrued_interest',
       'hardship_payoff_balance_amount']]
Hardship flag

'hardship_flag': factor que indica si el cliente tiene hardship plan en la actualidad. Sólo una persona tiene un plan de difultades en la actualidad, por lo que esta variable no presenta valor discriminante, y decidimos eliminarla.

In [233]:
hardship['hardship_flag'].value_counts()
Out[233]:
N    1283142
Y          1
Name: hardship_flag, dtype: int64
In [234]:
loan.drop(['hardship_flag'], axis=1, inplace = True)
In [235]:
loan.shape
Out[235]:
(1283143, 70)
Hardship type

Como anticipábamos en el epígrafe anterior, sólo existe un tipo de plan de contingencia (3 meses), por lo que utilizaremos esta variable como 'flag', para identificar qué usuario ha tenido concedido en algún momento un plan de dificultades. Como podemos observar, de los 1.306.387 casos totales, solamente 5.335 han esta condición. Decidimos imputar los valores ausentes con un string 'NO HARDSHIP PLAN' para evidenciar todavía más el valor dicotómico de esta variable, y convertimos en factor.

In [236]:
#solo existe un tipo de plan de contingencia: 3 meses.
loan['hardship_type'].value_counts()
Out[236]:
INTEREST ONLY-3 MONTHS DEFERRAL    5184
Name: hardship_type, dtype: int64
In [237]:
#Por exclusión, consideramos que las personas que no tienen un tipo de plan asignado, no tienen ninguno. 
loan['hardship_type'].isna().sum()
Out[237]:
1277959
In [238]:
#Imputamos un  string 'NO HARDSHIP PLAN' a cada NA
loan["hardship_type"].fillna("NO HARDSHIP PLAN", inplace = True) 
In [239]:
plot_var('hardship_type', 'Hardship type', continuous= False)
In [240]:
#convertimos en factor
loan['hardship_type'] = loan.hardship_type.astype('category')

Decidimos eliminar el resto de columnas dentro de este epígrafe, bien porque contienen información repetida (length, por ejemplo, ya que anteriormente hemos establecido que sólo hay planes a tres meses) o no suficientemente relevante para incluir en el modelo.

In [241]:
loan.drop(['hardship_reason', 'hardship_status',
       'deferral_term', 'hardship_amount', 'hardship_start_date',
       'hardship_end_date', 'payment_plan_start_date', 'hardship_length',
       'hardship_dpd', 'hardship_loan_status','hardship_last_payment_amount',
       'orig_projected_additional_accrued_interest',
       'hardship_payoff_balance_amount'], axis=1, inplace = True)
In [242]:
loan.shape
Out[242]:
(1283143, 57)

Disbursement method

Sólo encontramos una variable bajo este epígrafe, y hace referencia a la forma de recepción del préstamo: efectivo o transferencia bancaria. No estamos seguras de la relevancia de la variable, por lo que la incluimos inicialmente en el modelo, convirtiéndola en una variable categórica y evaluar posteriormente su impacto.

In [243]:
loan['disbursement_method'].value_counts()
Out[243]:
Cash         1277476
DirectPay       5667
Name: disbursement_method, dtype: int64
In [244]:
#comprobación de que no hay valores ausentes.
loan['disbursement_method'].isnull().sum()
Out[244]:
0
In [245]:
loan['disbursement_method']= loan.disbursement_method.astype('category')

Settlement

Este epígrafe hace referencia a las variables que analizan las variables relativas a 'settlement'. La liquidación de deudas es un acuerdo negociado en el que un prestamista acepta menos del monto adeudado, a veces significativamente menos, para liquidar legalmente una deuda.

Fuente: https://www.debt.org/settlement/ Dado que el inicio de este proceso implica haber incurrido en impago, de forma que el prestamista considera la deuda incobrable, decidimos prescindir de estas variables ya que, la información es redundante (la variable dependiente loan_Status ya contiene esta información y es la que tratamos de predecir). Información como la fecha de negociación o la cantidad que efectivamente se asume no es relevante.

In [246]:
settlement = loan[['debt_settlement_flag', 'debt_settlement_flag_date',
       'settlement_status', 'settlement_date', 'settlement_amount',
       'settlement_percentage', 'settlement_term']]
In [247]:
loan.drop(['debt_settlement_flag', 'debt_settlement_flag_date',
       'settlement_status', 'settlement_date', 'settlement_amount',
       'settlement_percentage', 'settlement_term'], axis=1, inplace = True)

Revisión del trabajo realizado.

Tras el trabajo de análisis exploratorio e ingeniería de datos realizado, procedemos a realizar una serie de comprobaciones posteriores, para verificar que el dataset tiene la forma deseada.

In [248]:
#Convertimos la variable objetivo en booleana
di = {"Default":1, "No Default":0}  
loan = loan.replace({"credit_risk": di})
loan.drop('loan_status', axis=1, inplace=True)
In [249]:
for col in loan.select_dtypes(include=['object']).columns:
    loan[col] = loan[col].astype('category')

Obtenemos las medidas básicas de cada variable, como medida adicional de control.

In [250]:
for col in loan.select_dtypes(include=['category']).columns:
    print ("Column {} has {} unique instances and NaN {}%".format( col, len(loan[col].unique()),round(loan[col].isna().sum()/len(loan)*100,2)) )
Column home_ownership has 4 unique instances and NaN 0.0%
Column verification_status has 2 unique instances and NaN 0.0%
Column initial_list_status has 2 unique instances and NaN 0.0%
Column hardship_type has 2 unique instances and NaN 0.0%
Column disbursement_method has 2 unique instances and NaN 0.0%
Column loan_amnt_range has 6 unique instances and NaN 0.0%
Column amt_difference has 2 unique instances and NaN 0.0%
Column purpose_g has 4 unique instances and NaN 0.0%
Column region has 5 unique instances and NaN 0.0%
In [251]:
for col in loan.select_dtypes(include=['number']).columns:
    print ("Column {}: Mean:{}, Min:{}, Max:{}, NaN: {}%".format( col,round(loan[col].mean(),2),round(loan[col].min(),2), round(loan[col].max(),2),round(loan[col].isna().sum()/len(loan)*100,2)) )
Column term: Mean:41.73, Min:36, Max:60, NaN: 0.0%
Column int_rate: Mean:13.23, Min:5.31, Max:30.99, NaN: 0.0%
Column installment: Mean:435.44, Min:4.93, Max:1719.83, NaN: 0.0%
Column grade: Mean:5.25, Min:1, Max:7, NaN: 0.0%
Column emp_length: Mean:5.65, Min:0.0, Max:10.0, NaN: 0.0%
Column annual_inc: Mean:4.82, Min:0.0, Max:7.04, NaN: 0.0%
Column dti: Mean:18.0, Min:-1.0, Max:49.96, NaN: 0.0%
Column mths_since_last_delinq: Mean:17.0, Min:0.0, Max:226.0, NaN: 0.0%
Column mths_since_last_record: Mean:11.96, Min:0.0, Max:129.0, NaN: 0.0%
Column open_acc: Mean:11.6, Min:0.0, Max:90.0, NaN: 0.0%
Column revol_util: Mean:51.93, Min:0.0, Max:892.3, NaN: 0.0%
Column collections_12_mths_ex_med: Mean:0.02, Min:0.0, Max:20.0, NaN: 0.0%
Column mths_since_last_major_derog: Mean:11.46, Min:0.0, Max:226.0, NaN: 0.0%
Column acc_now_delinq: Mean:0.01, Min:0.0, Max:14.0, NaN: 0.0%
Column tot_coll_amt: Mean:235.97, Min:0.0, Max:9152545.0, NaN: 0.0%
Column tot_cur_bal: Mean:132662.51, Min:0.0, Max:8000078.0, NaN: 0.0%
Column il_util: Mean:23.05, Min:0.0, Max:558.0, NaN: 0.0%
Column acc_open_past_24mths: Mean:4.51, Min:0.0, Max:64.0, NaN: 0.0%
Column avg_cur_bal: Mean:12663.02, Min:0.0, Max:958084.0, NaN: 0.0%
Column bc_open_to_buy: Mean:9615.45, Min:0.0, Max:559912.0, NaN: 0.0%
Column bc_util: Mean:57.16, Min:0.0, Max:339.6, NaN: 0.0%
Column chargeoff_within_12_mths: Mean:0.01, Min:0.0, Max:10.0, NaN: 0.0%
Column delinq_amnt: Mean:15.19, Min:0.0, Max:249925.0, NaN: 0.0%
Column mo_sin_old_il_acct: Mean:115.42, Min:0.0, Max:999.0, NaN: 0.0%
Column mo_sin_old_rev_tl_op: Mean:171.58, Min:0.0, Max:852.0, NaN: 0.0%
Column mo_sin_rcnt_tl: Mean:7.41, Min:0.0, Max:314.0, NaN: 0.0%
Column mort_acc: Mean:1.61, Min:0.0, Max:51.0, NaN: 0.0%
Column num_accts_ever_120_pd: Mean:0.48, Min:0.0, Max:51.0, NaN: 0.0%
Column num_sats: Mean:11.12, Min:0.0, Max:90.0, NaN: 0.0%
Column num_tl_90g_dpd_24m: Mean:0.08, Min:0.0, Max:39.0, NaN: 0.0%
Column percent_bc_gt_75: Mean:43.14, Min:0.0, Max:100.0, NaN: 0.0%
Column tax_liens: Mean:0.05, Min:0.0, Max:85.0, NaN: 0.0%
Column total_il_high_credit_limit: Mean:39617.76, Min:0.0, Max:2101913.0, NaN: 0.0%
Column credit_risk: Mean:0.2, Min:0, Max:1, NaN: 0.0%
Column issue_year: Mean:2014.87, Min:2007, Max:2018, NaN: 0.0%
Column Age_Borrower: Mean:20.88, Min:-0.0, Max:85.76, NaN: 0.0%
Column delinq_2yrs_cat: Mean:0.19, Min:0, Max:1, NaN: 0.0%
Column pub_rec_cat: Mean:0.17, Min:0, Max:1, NaN: 0.0%
Column acc_ratio: Mean:0.5, Min:0.0, Max:1.75, NaN: 0.0%
Column revol_bal_cat: Mean:1.0, Min:0, Max:1, NaN: 0.0%
In [252]:
loan = pd.get_dummies(loan, columns=loan.select_dtypes(include=['category']).columns)
In [253]:
loan['credit_risk'].value_counts(normalize=True)
Out[253]:
0    0.799936
1    0.200064
Name: credit_risk, dtype: float64
In [254]:
loan.shape
Out[254]:
(1283143, 69)

Selección de Variables

In [255]:
# get non-none values for each col
var_n = pd.DataFrame(loan.count()).reset_index()
var_n.columns=['index', 'n']

# get correlation with binary outcome
var_cor = pd.DataFrame((loan.corr()['credit_risk'])).reset_index()
var_cor.columns=['index', 'correlation']

# get data type
var_type = pd.DataFrame(loan.dtypes).reset_index()
var_type.columns=['index', 'type']
var_type

# load data dictionary
#var_dict = pd.read_csv('H:\\lending-club-loan-data\\dictionary.csv', encoding = "ISO-8859-1")
#var_dict.columns = ['index','Description']
Out[255]:
index type
0 term int64
1 int_rate float64
2 installment float64
3 grade int64
4 emp_length float64
5 annual_inc float64
6 dti float64
7 mths_since_last_delinq float64
8 mths_since_last_record float64
9 open_acc float64
10 revol_util float64
11 collections_12_mths_ex_med float64
12 mths_since_last_major_derog float64
13 acc_now_delinq float64
14 tot_coll_amt float64
15 tot_cur_bal float64
16 il_util float64
17 acc_open_past_24mths float64
18 avg_cur_bal float64
19 bc_open_to_buy float64
20 bc_util float64
21 chargeoff_within_12_mths float64
22 delinq_amnt float64
23 mo_sin_old_il_acct float64
24 mo_sin_old_rev_tl_op float64
25 mo_sin_rcnt_tl float64
26 mort_acc float64
27 num_accts_ever_120_pd float64
28 num_sats float64
29 num_tl_90g_dpd_24m float64
... ... ...
39 revol_bal_cat int64
40 home_ownership_MORTGAGE uint8
41 home_ownership_OTHER uint8
42 home_ownership_OWN uint8
43 home_ownership_RENT uint8
44 verification_status_1 uint8
45 verification_status_Not Verified uint8
46 initial_list_status_f uint8
47 initial_list_status_w uint8
48 hardship_type_INTEREST ONLY-3 MONTHS DEFERRAL uint8
49 hardship_type_NO HARDSHIP PLAN uint8
50 disbursement_method_Cash uint8
51 disbursement_method_DirectPay uint8
52 loan_amnt_range_0-5000 uint8
53 loan_amnt_range_5000-10000 uint8
54 loan_amnt_range_10000-15000 uint8
55 loan_amnt_range_15000-20000 uint8
56 loan_amnt_range_20000-25000 uint8
57 loan_amnt_range_25000+ uint8
58 amt_difference_Igual uint8
59 amt_difference_Menos uint8
60 purpose_g_debt uint8
61 purpose_g_life_event uint8
62 purpose_g_major_purchase uint8
63 purpose_g_other uint8
64 region_MidWest uint8
65 region_NorthEast uint8
66 region_SouthEast uint8
67 region_SouthWest uint8
68 region_West uint8

69 rows × 2 columns

In [256]:
import scipy
In [257]:
def do_test(x):
    # do t test for continuous var 
    if (x.dtypes == 'float64') | (x.dtypes == 'int64'):
        group1, group2 = [g[1] for g in x.groupby(loan['credit_risk'])]
        t, p = scipy.stats.ttest_ind(group1, group2,nan_policy='omit')
        if np.isnan(np.ma.getdata(t)):
            p=1
        return p
    
    # do chi squared test for categorical var
    if x.dtypes == 'object':
        observed = pd.crosstab(x, loan['credit_risk'])
        chi, p = scipy.stats.chi2_contingency(observed, correction=False)[0:2]
        return p
In [258]:
# calculate p values for all variables
pval = pd.DataFrame(loan.apply(do_test)).reset_index()
pval.columns=['index', 'p']
In [259]:
var_n = pd.DataFrame(loan.count()).reset_index()
var_n.columns=['index', 'n']

# get correlation with binary outcome
var_cor = pd.DataFrame((loan.corr()['credit_risk'])).reset_index()
var_cor.columns=['index', 'correlation']

# get data type
var_type = pd.DataFrame(loan.dtypes).reset_index()
var_type.columns=['index', 'type']
In [260]:
var_n.shape
Out[260]:
(69, 2)
In [261]:
# merger p value and variable info together and sort
var_info = pd.merge(var_n, pval, how='left', on=['index'])
var_info = pd.merge(var_info, var_type, how='left', on=['index'])
#var_info = pd.merge(var_info, var_dict, how='left', on=['index'])
var_select = var_info.loc[((var_info['n']/len(loan)>.95)) & (var_info['p'] < 0.05/len(var_info))]
var_select.to_csv('selected_vars.csv')

print('Total number of variables selected =',len(var_select))
print('Type of variables:')
print(var_select['type'].value_counts())

plt.plot(var_select['p'],'ro')
var_select.sort_values(by=['index'])
Total number of variables selected = 61
Type of variables:
float64    31
uint8      23
int64       7
Name: type, dtype: int64
Out[261]:
index n p type
35 Age_Borrower 1283143 0.000000e+00 float64
13 acc_now_delinq 1283143 4.104544e-06 float64
17 acc_open_past_24mths 1283143 0.000000e+00 float64
38 acc_ratio 1283143 0.000000e+00 float64
58 amt_difference_Igual 1283143 1.726919e-23 uint8
59 amt_difference_Menos 1283143 1.726919e-23 uint8
5 annual_inc 1283143 0.000000e+00 float64
18 avg_cur_bal 1283143 0.000000e+00 float64
19 bc_open_to_buy 1283143 0.000000e+00 float64
20 bc_util 1283143 0.000000e+00 float64
21 chargeoff_within_12_mths 1283143 7.062587e-04 float64
11 collections_12_mths_ex_med 1283143 7.036485e-75 float64
33 credit_risk 1283143 0.000000e+00 int64
36 delinq_2yrs_cat 1283143 6.032415e-99 int64
6 dti 1283143 0.000000e+00 float64
4 emp_length 1283143 1.138772e-204 float64
3 grade 1283143 0.000000e+00 int64
48 hardship_type_INTEREST ONLY-3 MONTHS DEFERRAL 1283143 0.000000e+00 uint8
49 hardship_type_NO HARDSHIP PLAN 1283143 0.000000e+00 uint8
40 home_ownership_MORTGAGE 1283143 0.000000e+00 uint8
42 home_ownership_OWN 1283143 3.729132e-09 uint8
43 home_ownership_RENT 1283143 0.000000e+00 uint8
16 il_util 1283143 0.000000e+00 float64
46 initial_list_status_f 1283143 1.537279e-19 uint8
47 initial_list_status_w 1283143 1.537279e-19 uint8
2 installment 1283143 0.000000e+00 float64
1 int_rate 1283143 0.000000e+00 float64
34 issue_year 1283143 0.000000e+00 int64
52 loan_amnt_range_0-5000 1283143 0.000000e+00 uint8
54 loan_amnt_range_10000-15000 1283143 7.479078e-34 uint8
... ... ... ... ...
56 loan_amnt_range_20000-25000 1283143 2.589719e-155 uint8
57 loan_amnt_range_25000+ 1283143 0.000000e+00 uint8
53 loan_amnt_range_5000-10000 1283143 0.000000e+00 uint8
23 mo_sin_old_il_acct 1283143 2.374473e-34 float64
24 mo_sin_old_rev_tl_op 1283143 0.000000e+00 float64
25 mo_sin_rcnt_tl 1283143 0.000000e+00 float64
26 mort_acc 1283143 0.000000e+00 float64
7 mths_since_last_delinq 1283143 2.247180e-16 float64
12 mths_since_last_major_derog 1283143 1.239574e-162 float64
8 mths_since_last_record 1283143 4.409626e-261 float64
27 num_accts_ever_120_pd 1283143 2.071184e-46 float64
28 num_sats 1283143 0.000000e+00 float64
29 num_tl_90g_dpd_24m 1283143 6.217691e-37 float64
9 open_acc 1283143 9.180317e-250 float64
30 percent_bc_gt_75 1283143 0.000000e+00 float64
37 pub_rec_cat 1283143 1.038922e-282 int64
61 purpose_g_life_event 1283143 6.509064e-113 uint8
62 purpose_g_major_purchase 1283143 1.129928e-88 uint8
63 purpose_g_other 1283143 1.994519e-14 uint8
65 region_NorthEast 1283143 2.575000e-24 uint8
66 region_SouthEast 1283143 1.385057e-29 uint8
68 region_West 1283143 2.440081e-91 uint8
39 revol_bal_cat 1283143 6.863130e-07 int64
10 revol_util 1283143 0.000000e+00 float64
31 tax_liens 1283143 1.855952e-30 float64
0 term 1283143 0.000000e+00 int64
15 tot_cur_bal 1283143 0.000000e+00 float64
32 total_il_high_credit_limit 1283143 7.856516e-10 float64
44 verification_status_1 1283143 0.000000e+00 uint8
45 verification_status_Not Verified 1283143 0.000000e+00 uint8

61 rows × 4 columns

In [262]:
#Solo las variables seleccionadas
drop_list = [col for col in loan.columns if col not in var_select['index'].tolist()]
drop_list
loan_select =loan.drop(labels=drop_list, axis=1)

Definimos una función para comprobar que efectivamente no quedan NAs que puedan dificultar la fase de modelaje y lo aplicamos al dataset:

In [263]:
# Define a function to visulize the features with missing values, and % of total values, & datatype
def missing_values_table(df):
     # Total missing values
    mis_val = df.isnull().sum()
    # Percentage of missing values
    mis_val_percent = 100 * df.isnull().sum() / len(df)
    mis_val_type = df.dtypes
    # Make a table with the results
    mis_val_table = pd.concat([mis_val, mis_val_percent, mis_val_type], axis=1)
     # Rename the columns
    mis_val_table_ren_columns = mis_val_table.rename(columns = {0 : 'Missing Values', 1 : '% of Total Values', 2: 'type'})
    # Sort the table by percentage of missing descending
    mis_val_table_ren_columns = mis_val_table_ren_columns[ mis_val_table_ren_columns.iloc[:,1] != 0].sort_values('% of Total Values', ascending=False).round(1)
    # Print some summary information
    print ("Your selected dataframe has " + str(df.shape[1]) + " columns.\n" "There are " + str(mis_val_table_ren_columns.shape[0]) + " columns that have missing values.")
    # Return the dataframe with missing information
    return mis_val_table_ren_columns
In [264]:
missing_values_table(loan)
Your selected dataframe has 69 columns.
There are 0 columns that have missing values.
Out[264]:
Missing Values % of Total Values type
In [265]:
loan_select.to_csv('../data/2_EDAoutput.gz', compression='gzip')